Alfred Vahau
Mar 11 2005, 03:37 PM
Like:
perl -e "print "Hello World!n";"
alfred,
renard wrote:
QUOTE |
I am running ActivePerl 5.8.6 on Windows XP.
I am unable to execute a statement like -- perl -e '<perl code>' -- I always get this response: Can't find string terminator "'" anywhere before EOF at -e line 1.
Does not matter if I use (', ", or `) .. same response expect it can't find the string terminator matching the used quotation mark.
What am I doing wrong?
Thank you for any assistance you may give me.
|
--
Perl -
"... making the easy jobs easy,
without making the hard jobs impossible."
'The Camel', 3ed
----- Original Message -----
From: "renard" <[Email Removed]>
To: "Perl Beginners List" <[Email Removed]>
Sent: Friday, March 11, 2005 9:23 AM
Subject: Executing perl code on the command line
QUOTE |
I am running ActivePerl 5.8.6 on Windows XP.
I am unable to execute a statement like -- perl -e '<perl code>' -- I always get this response: Can't find string terminator "'" anywhere before EOF at -e line 1.
Does not matter if I use (', ", or `) .. same response expect it can't find the string terminator matching the used quotation mark.
|
Try printing this :)
perl -e "print 'Hello World'"
QUOTE |
What am I doing wrong?
Thank you for any assistance you may give me.
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
John W. Krahn
Mar 11 2005, 03:51 PM
FlashMX wrote:
Hello,
QUOTE |
I need to modify some existing code. The below line checks a file I'm reading in and does a search/replace based on the match. Currently I'm looking for...
if (/00000 set/) { ...etc.
Because the "000000" can change to different numbers (but always 6 figures which could include a period) how can I do a wildcard search?
For example I also need to search for ".00000". Or it could also be ".45306" or "123456" etc.
if (/WILDCARD set/) { ...etc.
|
If the decimal point will always be at the beginning of the number:
/(?:.d{5}|d{6}) set/
John
--
use Perl;
program
fulfillment
Luke Bakken
Mar 11 2005, 03:52 PM
QUOTE |
I am unable to execute a statement like -- perl -e '<perl code>' -- I always get this response: Can't find string terminator "'" anywhere before EOF at -e line 1.
|
From the command line, use " " to quote your code and qq() or q() as
quotes inside your code:
c:>perl -e"print qq(Hellon)"
John W. Krahn
Mar 11 2005, 03:53 PM
John W. Krahn wrote:
QUOTE |
FlashMX wrote:
I need to modify some existing code. The below line checks a file I'm reading in and does a search/replace based on the match. Currently I'm looking for...
if (/00000 set/) { ...etc.
Because the "000000" can change to different numbers (but always 6 figures which could include a period) how can I do a wildcard search?
For example I also need to search for ".00000". Or it could also be ".45306" or "123456" etc.
if (/WILDCARD set/) { ...etc.
If the decimal point will always be at the beginning of the number:
/(?:.d{5}|d{6}) set/
|
Or:
/[.d]d{5} set/
John
--
use Perl;
program
fulfillment
FlashMX
Mar 11 2005, 03:55 PM
QUOTE |
FlashMX wrote: Cool...that worked...thanks
I forgot to mention that one the match is found I do a search and replace
if (/[0-9.]{6} setgray/) { s/.90000 set/-50.2 v n.90000 set/;
This is the issue. I need to "grab" the match number (whatever it is) and add it into the s/
So...
if (/[0-9.]{6} setgray/) { s/NUMBER_FROM_ABOVE set/-50.2 v nNUMBER_FROM_ABOVE set/;
perldoc perlretut perldoc perlre
You need to capture the value then...
if (/([0-9.]{6}) setgray/) { s/$1 set/-50.2 v n$1 set/; }
Which can be shortened more, but I would leave it readable. Capture values with ()'s and then use those ordered matches by accessing, $1, $2, $3, etc.
http://danconia.org
|
Hmm...I just tried the above and nothing gets replaced in my output file. Could it be the syntax?
if (/([0-9.]{6}) set/) {
s/$1 set/-50.2 v n$1 set/;
FlashMX
Mar 11 2005, 03:57 PM
On Fri, 11 Mar 2005 07:53:30 -0800, John W. Krahn wrote:
QUOTE |
John W. Krahn wrote: FlashMX wrote:
I need to modify some existing code. The below line checks a file I'm reading in and does a search/replace based on the match. Currently I'm looking for...
if (/00000 set/) { ...etc.
Because the "000000" can change to different numbers (but always 6 figures which could include a period) how can I do a wildcard search?
For example I also need to search for ".00000". Or it could also be ".45306" or "123456" etc.
if (/WILDCARD set/) { ...etc.
If the decimal point will always be at the beginning of the number:
/(?:.d{5}|d{6}) set/
Or:
/[.d]d{5} set/
|
Not sure if the decimal would always be at the beginning. I guess I have to take into considering it could fall at the beginning, middle or even the end.
John W. Krahn
Mar 11 2005, 03:58 PM
FlashMX wrote:
QUOTE |
Cool...that worked...thanks
I forgot to mention that one the match is found I do a search and replace
if (/[0-9.]{6} setgray/) { s/.90000 set/-50.2 v n.90000 set/;
This is the issue. I need to "grab" the match number (whatever it is) and add it into the s/
So...
if (/[0-9.]{6} setgray/) { s/NUMBER_FROM_ABOVE set/-50.2 v nNUMBER_FROM_ABOVE set/;
|
if ( s/(?=[d.]{6} set)/-50.2 v n/ ) {
do_something_else();
}
John
--
use Perl;
program
fulfillment
FlashMX
Mar 11 2005, 04:37 PM
On Fri, 11 Mar 2005 10:57:19 -0500, FlashMX wrote:
QUOTE |
On Fri, 11 Mar 2005 07:53:30 -0800, John W. Krahn wrote:
John W. Krahn wrote: FlashMX wrote:
I need to modify some existing code. The below line checks a file I'm reading in and does a search/replace based on the match. Currently I'm looking for...
if (/00000 set/) { ...etc.
Because the "000000" can change to different numbers (but always 6 figures which could include a period) how can I do a wildcard search?
For example I also need to search for ".00000". Or it could also be ".45306" or "123456" etc.
if (/WILDCARD set/) { ...etc.
If the decimal point will always be at the beginning of the number:
/(?:.d{5}|d{6}) set/
Or:
/[.d]d{5} set/
Not sure if the decimal would always be at the beginning. I guess I have to take into considering it could fall at the beginning, middle or even the end.
|
I tried to search for the word "test" followed by a wordspace and a return then the text 123456 text
test
123456 set
Whats wrong with the syntax?
if (/test ^123456 set/) {
FlashMX
Mar 11 2005, 05:13 PM
Why does this syntax not work? The $1 does not come out.
if (/([0-9.]{6}) set/) {
s/$1 set/n-50.2 v n$1 set/;
Stone
Mar 11 2005, 06:07 PM
QUOTE |
if (/([0-9.]{6}) set/) { s/$1 set/n-50.2 v n$1 set/;
|
You need to escape the period or it will match any character but
newline. As it is right now you'll match ".FANTA", which isn't what
you want.
QUOTE |
Why does this syntax not work? The $1 does not come out.
|
You can't use variables in the regex portion of your substitution. If
all you're going to do is a substitution you don't need the if
statement. However, either way, this is probably the substitution
you're looking for:
s/([0-9.]{6}) set/n-50.2 v n$1 set/;
Have a good one.
John W. Krahn
Mar 11 2005, 06:16 PM
Stone wrote:
QUOTE |
if (/([0-9.]{6}) set/) { s/$1 set/n-50.2 v n$1 set/;
You need to escape the period or it will match any character but newline. As it is right now you'll match ".FANTA", which isn't what you want.
|
A character class is not the same as a regular expression and the period in a
character class is just a period and will only match a period while in a
regular expression it is a meta-character that matches any non-newline
character.
John
--
use Perl;
program
fulfillment
Renard
Mar 12 2005, 03:23 PM
Thank you. your methods work fine.
I do wonder ... I have seen and tried command line perl code examples from
this mailing list that did not have quotes for print statements.
On my computer they did not work.. Is this specific to Windows XP and
ActivePerl? Or was it untested code?
PS: using single quote around the perl code fails...need to use double
quotes.
----- Original Message -----
From: "Bakken, Luke" <[Email Removed]>
To: "renard" <[Email Removed]>; "Perl Beginners List" <[Email Removed]>
Sent: Friday, March 11, 2005 10:52 AM
Subject: RE: Executing perl code on the command line
QUOTE |
I am unable to execute a statement like -- perl -e '<perl code>' -- I always get this response: Can't find string terminator "'" anywhere before EOF at -e line 1.
|
From the command line, use " " to quote your code and qq() or q() as
quotes inside your code:
c:>perl -e"print qq(Hellon)"
Juan Gomez
Mar 12 2005, 03:40 PM
Hi !!!
For me the line work here:
C:>perl -e "print qq(Hellon)"
Hello
C:>perl -e"print qq(Hellon)"
Hello
Can it be that you type it wrong?
Or check your perl version
C:>perl -v
-----Original Message-----
From: renard [mailto:[Email Removed]]
Sent: Saturday, March 12, 2005 9:24 AM
To: Perl Beginners List
Cc: Bakken, Luke; perlmails@thinbrowser
Subject: Re: Executing perl code on the command line
Thank you. your methods work fine.
I do wonder ... I have seen and tried command line perl code examples from
this mailing list that did not have quotes for print statements.
On my computer they did not work.. Is this specific to Windows XP and
ActivePerl? Or was it untested code?
PS: using single quote around the perl code fails...need to use double
quotes.
----- Original Message -----
From: "Bakken, Luke" <[Email Removed]>
To: "renard" <[Email Removed]>; "Perl Beginners List" <[Email Removed]>
Sent: Friday, March 11, 2005 10:52 AM
Subject: RE: Executing perl code on the command line
QUOTE |
I am unable to execute a statement like -- perl -e '<perl code>' -- I always get this response: Can't find string terminator "'" anywhere before EOF at -e line 1.
|
From the command line, use " " to quote your code and qq() or q() as
quotes inside your code:
c:>perl -e"print qq(Hellon)"
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Jonathan Paton
Mar 12 2005, 04:11 PM
QUOTE |
You should not fiddle with $[ though. Unless you are creating an entry into the obfuscated code contest or a YAPH.
|
Thanks for the idea :)
@words = ("another ", "hackern", "Just ", "Perl ");
eval '$[=' . $_ . ';print $words[3]' for 1, 3, 0, 2;
The eval is required because you can only set $_ to a constant
value.
Jonathan Paton
--
#!perl
$J=' 'x25 ;for (qq< 1+10 9+14 5-10 50-9 7+13 2-18 6+13
17+6 02+1 2-10 00+4 00+8 3-13 3+12 01-5 2-10 01+1 03+4
00+4 00+8 1-21 01+1 00+5 01-7 >=~/ SS SS /gx) {m/(
d+) (.+) /x,, vec$ J,$p +=$2 ,8,= $c+= +$1} warn $J,,
Hendrik Maryns
Mar 12 2005, 04:20 PM
Jonathan Paton schreef:
QUOTE |
You should not fiddle with $[ though. Unless you are creating an entry into the obfuscated code contest or a YAPH.
Thanks for the idea :)
@words = ("another ", "hackern", "Just ", "Perl "); eval '$[=' . $_ . ';print $words[3]' for 1, 3, 0, 2;
The eval is required because you can only set $_ to a constant value.
|
Nice one! I even think I understand it :-p
Shouldn't there be a ; after [3]? But no, let me guess: you don't need
to type the last ; of your program?
H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare
Renard
Mar 12 2005, 08:15 PM
Hi,
perl -e "print qq(Hellon)" works fine for me.
What does not work is : perl -e 'print qq(Hellon)'
----- Original Message -----
From: "Gomez, Juan" <[Email Removed]>
To: "renard" <[Email Removed]>; "Perl Beginners List" <[Email Removed]>
Cc: "Bakken, Luke" <[Email Removed]>;
<[Email Removed]>
Sent: Saturday, March 12, 2005 10:40 AM
Subject: RE: Executing perl code on the command line
QUOTE |
Hi !!!
For me the line work here:
C:>perl -e "print qq(Hellon)" Hello
C:>perl -e"print qq(Hellon)" Hello
Can it be that you type it wrong? Or check your perl version
C:>perl -v
-----Original Message----- From: renard [mailto:[Email Removed]] Sent: Saturday, March 12, 2005 9:24 AM To: Perl Beginners List Cc: Bakken, Luke; perlmails@thinbrowser Subject: Re: Executing perl code on the command line
Thank you. your methods work fine.
I do wonder ... I have seen and tried command line perl code examples from this mailing list that did not have quotes for print statements.
On my computer they did not work.. Is this specific to Windows XP and ActivePerl? Or was it untested code?
PS: using single quote around the perl code fails...need to use double quotes.
----- Original Message ----- From: "Bakken, Luke" <[Email Removed] To: "renard" <[Email Removed]>; "Perl Beginners List" <[Email Removed] Sent: Friday, March 11, 2005 10:52 AM Subject: RE: Executing perl code on the command line
I am unable to execute a statement like -- perl -e '<perl code>' -- I always get this response: Can't find string terminator "'" anywhere before EOF at -e line 1.
From the command line, use " " to quote your code and qq() or q() as quotes inside your code:
c:>perl -e"print qq(Hellon)"
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response |
Juan Gomez
Mar 12 2005, 08:21 PM
Single quotations?
Those are for Unix/Linux perl only
For windows we have to stick to double qoutation marks
--well that's what I remmeber from quigley's book (Perl by example)
:o)
-----Original Message-----
From: renard [mailto:[Email Removed]]
Sent: Saturday, March 12, 2005 2:15 PM
To: Perl Beginners List
Cc: Gomez, Juan
Subject: Re: Executing perl code on the command line
Hi,
perl -e "print qq(Hellon)" works fine for me.
What does not work is : perl -e 'print qq(Hellon)'
----- Original Message -----
From: "Gomez, Juan" <[Email Removed]>
To: "renard" <[Email Removed]>; "Perl Beginners List" <[Email Removed]>
Cc: "Bakken, Luke" <[Email Removed]>;
<[Email Removed]>
Sent: Saturday, March 12, 2005 10:40 AM
Subject: RE: Executing perl code on the command line
QUOTE |
Hi !!!
For me the line work here:
C:>perl -e "print qq(Hellon)" Hello
C:>perl -e"print qq(Hellon)" Hello
Can it be that you type it wrong? Or check your perl version
C:>perl -v
-----Original Message----- From: renard [mailto:[Email Removed]] Sent: Saturday, March 12, 2005 9:24 AM To: Perl Beginners List Cc: Bakken, Luke; perlmails@thinbrowser Subject: Re: Executing perl code on the command line
Thank you. your methods work fine.
I do wonder ... I have seen and tried command line perl code examples from this mailing list that did not have quotes for print statements.
On my computer they did not work.. Is this specific to Windows XP and ActivePerl? Or was it untested code?
PS: using single quote around the perl code fails...need to use double quotes.
----- Original Message ----- From: "Bakken, Luke" <[Email Removed] To: "renard" <[Email Removed]>; "Perl Beginners List" <[Email Removed] Sent: Friday, March 11, 2005 10:52 AM Subject: RE: Executing perl code on the command line
I am unable to execute a statement like -- perl -e '<perl code>' -- I always get this response: Can't find string terminator "'" anywhere before EOF at -e line 1.
From the command line, use " " to quote your code and qq() or q() as quotes inside your code:
c:>perl -e"print qq(Hellon)"
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/ <http://learn.perl.org/first-response |
Hendrik Maryns
Mar 13 2005, 10:13 AM
Gomez, Juan schreef:
QUOTE |
Single quotations? Those are for Unix/Linux perl only
For windows we have to stick to double qoutation marks --well that's what I remmeber from quigley's book (Perl by example)
:o)
|
Indeed, read perldoc perlrun, especially the part about #!
H.
--
Hendrik Maryns
Interesting websites:
www.lieverleven.be (I cooperate)
www.eu04.com European Referendum Campaign
aouw.org The Art Of Urban Warfare
Marcos Rebelo
Mar 14 2005, 08:43 AM
This was not a home work. In a real script I need to change the last
element of the array. Not changing the array it self.
I work with Perl for more than 4 years now. And after 4 years, I need this.
Thanks
MArcos
On Thu, 10 Mar 2005 09:06:52 -0600, Larsen, Errin M HMMA/IT
<[Email Removed]> wrote:
QUOTE |
-----Original Message----- From: Wiggins d'Anconia [mailto:[Email Removed]] Sent: Thursday, March 10, 2005 8:55 AM To: Marcos Rebelo Cc: Perl Beginners Subject: Re: Simplify perl -e '$a = [1,2,3,4,7]; print $a->[$#{@$a}]'
Marcos Rebelo wrote: This is correctly printing '7' but '$a->[$#{@$a}]' seems to be encripted code.
Can I write this in a cleaner way?
$a->[-1]; ???
Hi Wiggins,
for those of us tryin' to keep up at home, can you walk us through that bit a little?
Here's what I spot:
$a = [1,2,3,4,7] # this is initializing a scalar, $a, with a reference to an array, [1,2,3,4,7]
# $a-> this is dereferencing the array # as I understand it, and I really don't, the $#ARRAYNAME will give you the number of elements, minus one, of an array? # if that is the case, and then {@$a} ALSO derefernces the array, so then # $#{@$a} will be the number of elements in the array referenced by $a, minus one (or, '4', in this example)
# so print $a->[$#{@$a}]
# is equivelant to print $a->[4]
# or, since $#{@$a} will always be the index of the last element of the array: print $a->[-1]
Did I get it right? That looks like homework to me ... Why would you ever do that in a practical script?
--Errin
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed] <http://learn.perl.org/> <http://learn.perl.org/first-response
|
Jeff 'japhy' Pinyan
Mar 15 2005, 12:13 AM
On Mar 14, Peter Rabbitson said:
QUOTE |
sub sub_call {
my ($hashref, $object) = @_;
print "Now working on $object using valuesn";
foreach my $key (keys %{${$hahsref}{$object}}) {
print "$keyn"; } }
Simple enough right? What I was asking is how can I get the same result without passing 'abcd' and a reference to the outter hash, but by passing ONLY a reference to the inner hash. Actually the more I think about it the more I figure it can't be done, since references are symbolic and don't carry information about upper (or technically lower) level structures as the outer hash that contains the actual key name... Am I correct? :)
|
If you're asking how you can pass $hash{abcd} to the function and
determine, IN the function, that you're working with the key 'abcd' from
the outside hash, there is no way of doing that.
And once again, you've written some round-about referencing code:
# from the first email in this thread
another_nasty_sub(%{$hash{abcd}});
which should just be
another_nasty_sub($hash{abcd});
Then above, you have
foreach my $key (keys %{${$hahsref}{$object}}) {
which looks very messy. It works, but it's got a lot of extra braces.
I'd use one of the following:
foreach my $key (keys %{ $$hashref{$object} }) {
# or
foreach my $key (keys %{ $hashref->{$object} }) {
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
Jeff 'japhy' Pinyan
Mar 15 2005, 12:58 AM
On Mar 15, Peter Rabbitson said:
QUOTE |
<sigh>... I'll get it some day. As far as dereferencing with ->, which I asked earlier but I never got an answer to. For example are
$sources{${$batch_ref}{by_method}}{card_def}
and
$sources->($batch_ref->by_method)->card_def
|
No, not at all.
$sources{${$batch_ref}{by_method}}{card_def}
is the same as
$sources{$batch_ref->{by_method}}{card_def}
Here is what it comes down to. When you have a REFERENCE on the left side
and a subscript on the right side, you can use a -> in between them:
my $a_ref = [10, 20, 30, 40];
print $a_ref->[2];
That is the same as $$a_ref[2]. $$a_ref[2] is the same as ${$a_ref}[2].
The idea there is that the name of the array goes inside the $...[2], and
here, the "name" of our array is $a_ref. If it were something much more
complex, we would wrap it in braces {...}. You might end up having
something like ${$foo{bar}[2]}[5]. Using arrow notation, that would be
written as $foo{bar}[2]->[5].
Finally, when you have two subscripts with an arrow between them, the
arrow can be removed with no effect -- it's implied. $foo{bar}[2][5] is
the same as $foo{bar}[2]->[5] which is the same as $foo{bar}->[2]->[5]
which is the same as the ugly ${ ${ $foo{bar} }[2] }[5].
Read 'perlreftut' for more details.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
http://japhy.perlmonk.org/ % have long ago been overpaid?
http://www.perlmonks.org/ % -- Meister Eckhart
Chris Devers
Mar 16 2005, 04:14 PM
On Wed, 16 Mar 2005, Paul Ohashi wrote:
QUOTE |
I can't see enough to determine why your script is failing, but the four lines below work as expected:
#!/usr/local/bin/perl $logFile = '/home/paulo/mylog.log'; $myCmd = 'ls -l'; system ("$myCmd | tee -a $logFile");
Hope this helps...
|
Is there some reason that everyone has latched onto the system `tee`
command rather than doing this in Perl?
The "tctee" program shown in _Perl Cookbook_ (either edition) shows how
to do this directly in Perl. The program in question can be downloaded
from the book's site (click on "examples") --
<http://www.oreilly.com/catalog/cookbook/>
<http://www.oreilly.com/catalog/perlckbk2/>
-- or from this Sourceforge page --
<http://pleac.sourceforge.net/pleac_perl/filecontents.html#AEN487>
There's no clear reason to prefer an external program to do this job.
--
Chris Devers
Dave Gray
Mar 16 2005, 07:30 PM
QUOTE |
blade:~/personal/perl > cat -n check.p 1 #!/usr/bin/perl 2 3 use Net::Telnet; 4 5 $timeout = 10; 6 $obj=new Net::Telnet( [Timeout => $timeout,] ); 7 blade:~/personal/perl > perl check.p unknown remote host: ARRAY(0x22494) at check.p line 6 blade:~/personal/perl
|
[Timeout => $timeout.] creates an array reference, which when printed
out, in your case gave 'ARRAY(0x22494)'. If you check the docs for
Net::Telnet[1], I think you'll find the answer to your problem in the
first example.
[1] <http://search.cpan.org/~jrogers/Net-Telnet-3.03/lib/Net/Telnet.pm>
Chris Devers
Mar 22 2005, 01:30 PM
On Tue, 22 Mar 2005, Atul Vohra wrote:
QUOTE |
I was hoping somebody actually handing me code snippets :-)
|
Keep hoping then.
This list is not a script writing service.
You were pointed towards a CPAN search for SOAP modules; the
documentation for most or all of these will include code.
Look there, try that, then if you have problems, let us know.
--
Chris Devers
Thomas Btzler
Mar 24 2005, 02:18 PM
David Jacopille <[Email Removed]> wrote:
[...]
QUOTE |
While the foo.lock is a good idea I would still have to somehow detect that the system's "Print Manager" is done writing the file to know when to remove the foo.lock - which means I'm back to needing the ability to ask ask when the file is finished writing. If I can successfully do that I wouldn't need the foo.lock.
|
What's your target OS? On Win32 you could try and do nasty
things like trying to open a file for writing (in append
mode) to find out if it's still being written to.
On Linux, you might be able to move the destination file to
another directory while it's still being written to. You could
then chekc the directory to see when a new file is created,
which would presumably mean that the spooler would be done
with your file.
Just my $0.02,
Thomas
Steven Schubiger
Mar 26 2005, 08:25 AM
On 26 Mar, Brett Williams wrote:
QUOTE |
What i would like is for the output to look like
1: 1002.00 2: 125.00 3: 61864.35 4: 890876.99 5: 9.99
but perl doesn't like my code.
|
#! /usr/bin/perl
use strict;
use warnings;
my $lnum = 1;
while (my $line = <DATA>) {
next unless $line =~ /d+/;
chomp($line);
my ($value) = $line =~ /^?.*?<(.+?)>$/;
print $lnum++, ": $valuen";
}
__DATA__
?<1002.00>
?<125.00>
?<61864.35>
?<890876.99>
?<9.99>
Steven Schubiger
Mar 26 2005, 08:31 AM
It's superfluous in this peculiar case, by the way.
Steven Schubiger
Mar 28 2005, 12:10 PM
QUOTE |
On 28 Mar, marcos rebelo wrote:
I have a program that is supposed to send files throw FTP. And I'm using the Net::FTP. I have a destiny path and I need to create the directories if they don't exist.
|
Locally or remotely?
QUOTE |
How do I check if a Directory exist?
|
-e $dir for local purposes
Steven
Offer Kaye
Mar 30 2005, 09:21 AM
On 29 Mar 2005 10:19:09 -0800, Randal L. Schwartz wrote:
QUOTE |
No, you should change it only when appropriate. "35.0" is not eq to "35", and yet they are numerically equal.
|
Dratz, foiled again! ;-)
QUOTE |
I hope you don't write the rest of your code like that. :(
|
In this specific case I had no way to know what the OP has as data,
numbers or strings, so I assumed the general case. If you have strings
and use the "==" operator, you get warnings, no way around that (I'm
assuming "use warnings;" in effect). No only that, use also get a
wrong answer (e.g. "a" == "b" is TRUE).
If you use "eq" and are trying to find "35.0" when the string "35" is
the one you really want, and get a "no match" result, I would say that
is the correct behaviour and the "no match" result is actually
correct, or at least less wrong, since if you have both strings and
numbers I see no way to use "==" for comparison without getting false
results. Am I right?
Regards,
--
Offer Kaye
Chris Devers
Mar 30 2005, 02:11 PM
On Thu, 31 Mar 2005, Ankur Gupta wrote:
QUOTE |
No I do not [want to] die so fast.. I want to do some processing based on the died message.
|
Fine then.
eval {
risky_action();
}
if $@ {
my $status = $@;
my $result = do_some_processing();
die "Got $status, did some processing: $resultn";
}
This should work.
--
Chris Devers
Randal L. Schwartz
Mar 30 2005, 03:09 PM
QUOTE |
"Offer" == Offer Kaye <[Email Removed]> writes:
|
Offer> In this specific case I had no way to know what the OP has as data,
Offer> numbers or strings, so I assumed the general case.
No, the point here is that THERE IS NO GENERAL CASE.
You either want numeric comparisons, or string comparisons. You can't
use string comparisons for "both".
That's why I keep correcting you.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Wim W Olivier
Mar 31 2005, 01:05 PM
Thanks Offer! It's working!
Wim
-----Original Message-----
From: Offer Kaye [mailto:[Email Removed]]
Sent: 31 March 2005 02:55 PM
To: Perl Beginners
Subject: Re: Question: Array of Hashes
On Thu, 31 Mar 2005 14:40:47 +0200, Olivier, Wim W wrote:
QUOTE |
Hi all,
I have the following code below which I need to modify a bit.
The script currently lists the key/value pairs for all processes in the system. What I need to achieve is for it to only list the key/value pairs for processes of which the "Description" key is of a certain ASCII value, say "analytics.exe".
|
Untested, but here goes:
foreach my $info (@info)
{
if ($info->{'Description'} eq "analytics.exe")
{
foreach ('ProcessId', 'Description', 'ThreadCount')
{
print "$_ = ", $info->{$_} || '', "n";
}
print "n";
}
}
Hope this helps,
--
Offer Kaye
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
________________________________________________________________________________
__________________________________________________
Standard Bank Disclaimer and Confidentiality Note
This e-mail, its attachments and any rights attaching hereto are, unless the context clearly indicates otherwise, the property of Standard Bank Group Limited and/or its subsidiaries ("the Group"). It is confidential, private and intended for the addressee only.
Should you not be the addressee and receive this e-mail by mistake, kindly notify the sender, and delete this e-mail, immediately and do not disclose or use same in any manner whatsoever.
Views and opinions expressed in this e-mail are those of the sender unless clearly stated as those of the Group. The Group accepts no liability whatsoever for any loss or damages whatsoever and howsoever incurred, or suffered, resulting, or arising, from the use of this email or its attachments.
The Group does not warrant the integrity of this e-mail nor that it is free of errors, viruses, interception or interference.
Licensed divisions of the Standard Bank Group are authorised financial services providers in terms of the Financial Advisory and Intermediary Services Act, No 37 of 2002 (FAIS).
For information about the Standard Bank Group Limited visit our website
http://www.standardbank.co.za ________________________________________________________________________________
___________________________________________________
Bob Showalter
Apr 1 2005, 04:44 PM
[Email Removed] wrote:
QUOTE |
I am trying to build an inheritable object, and I am using examples from the Perl Cookbook, 2nd edition, mostly Recipe 13.1, using the new and _init methods.
|
Your subclass does not need (and should not have) a new() method; it can use
the one from the base class.
As Randal pointed out, the subclass _init needs to call
$self->SUPER::_init(), and then do any additional initialization. If there
is no additional initialization in the subclass, you don't need an _init
method there either.
Thomas Btzler
Apr 4 2005, 12:49 PM
John <[Email Removed]> said:
QUOTE |
Ing. Branislav Gerzo <[Email Removed]> suggested:
J>> I cannot find GeoIPCity.dat for downloading. J>> Has anyone tried that?
just use google: http://www.maxmind.com/download/geoip/database/
That database is only for the country, not the cities.
|
Bob Showalter
Apr 4 2005, 01:06 PM
Nicolay Vasiliev wrote:
QUOTE |
Hello there!
I tried to execute many SQL-clauses ";" separated by DBI::do() method but got an error message about SQL syntax mistake.
|
You must execute statements one at a time with do(). Don't add semicolons at
the end.
QUOTE |
If I execute the same SQL from MySQL shell or some MySQL GUI all works fine.
|
Those tools are internally splitting the script into separate statements and
executing them on at a time. When you use DBI, you have to do this splitting
yourself.
QUOTE |
Is DBI::do() method able to perform many SQL clauses at all? If no what method or function should I use to perform this?
|
There is a DBI::Shell module on CPAN you might want to look at. I have not
used it myself, so I can't comment on how well it works...
Bob Showalter
Apr 4 2005, 02:55 PM
Michael Gale wrote:
QUOTE |
... m|output:DISK (w+) [(d+) kB ((d+)%) free on (S+)]| and do { my $status = $1; my $kb_free = $2; my $pct_free = $3; my $mount = $4; push @s, [ $mount, [ blockpct, GAUGE, $pct_free ] ]; };
I do not understand the "and do" option.
|
"do" here turns a block into an expression. The "and" causes the RHS to be
evaluated if the LHS is true. In otherwords, if the m|| match succeeds,
evaluate the stuff in the do {} block. This notation is legal, but a bit
unusual. The equivalent, and more common construct would be:
if (m|output:DISK (w+) [(d+) kB ((d+)%) free on (S+)]|) {
my $status = $1;
my $kb_free = $2;
my $pct_free = $3;
my $mount = $4;
push @s, [ $mount, [ blockpct, GAUGE, $pct_free ] ];
};
The important thing for both formats is to always test whether the pattern
match succeeds before attempting to use $1, $2, etc.
Thomas Btzler
Apr 5 2005, 05:25 AM
Harold Castro <[Email Removed]> wrote:
QUOTE |
I'm parsing a log file that contains this format:
31388202 181264589 8843 59460 8843 59460 10728 59045 10728 59045 10617 59006 10728 59045 8693 58389 9531 59661
These logs are in unix timestamp format: I'm trying to convert the first column into scalar localtime.
|
Why not do it the simple way:
while( <FILE> ){
s/^(d+)/scalar localtime( $1 )/e;
print;
}
or even simpler on the command line:
perl -pne 's/^(d+)/scalar localtime( $1 )/e'
HTH,
Thomas
John Moon
Apr 5 2005, 12:52 PM
Subject: datetime comparisons
hello all
i am wondering a there is a module that do comparisons
between two different datetime stamps
for example
2/4/2005:15:20:20 and 4/4/2005:12:09:23
which date is bigger (namely earliest)
You may wish to look at "Time::Local". This will convert the strings to
seconds then they can be compared...
Hope this gives you some ideas...
jwm
Chris Devers
Apr 6 2005, 02:45 PM
On Wed, 6 Apr 2005, Debbie Cooper wrote:
QUOTE |
So the sub directories in DirA will be combined with like-named sub directories in DirB and they will move up a level in the hierarchy.
|
Why aren't you using rsync for this?
You can write it by hand in Perl, but rsync is the Swiss Army knife of
file copy tools; a problem like this would be no trouble at all with it.
$ rsync dir1 dir2 targetdir
There are dozens of command line flags that can fine-tune this, but even
this simple version should get you close to what you need.
Rsync examples:
http://samba.anu.edu.au/rsync/examples.htmlIt looks like you may be a Windows user. If you have Cygwin, rsync is
available there, or you can follow instructions similar to these:
http://optics.ph.unimelb.edu.au/help/rsync/rsync_pc1.htmlPerl's a great tool, but sometimes, other things are *much* easier.
--
Chris Devers
Chris Devers
Apr 6 2005, 05:22 PM
On Wed, 6 Apr 2005, John W. Krahn wrote:
QUOTE |
So it wasn't that bad of an example.
|
I still prefer this though:
$ rsync dir1 dir2 targetdir
Yours is still way too verbose :-)
--
Chris Devers
JupiterHost.Net
Apr 6 2005, 07:56 PM
QUOTE |
I want to copy these directories so that the target directory looks like this:
Target directory structure
SubDirAA combined directories SubDirAB combined directories SubDirAC combined directories SubDirBC combined directories
|
How about this (or a variation for your specific needs)
#!/usr/bin/perl
use strict;
use warnings;
use File::Copy::Recursive qw(dircopy);
my $dira = 'foo';
my $dirb = 'bar';
my $target = 'baz';
dircopy($dira,$target) or die $!;
dircopy($dirb,$target) or die $!;
http://search.cpan.org/~dmuey/File-Copy-Re...05/Recursive.pmHTH :)
Lee.M
John W. Krahn
Apr 6 2005, 08:56 PM
Debbie Cooper wrote:
QUOTE |
I need to combine directories as follows:
Source directory structure:
DirA SubDirAA More directories SubDirAB More directories SubDirAC More directories DirB SubDirAA More directories SubDirAB More directories SubDirBC More directories
I want to copy these directories so that the target directory looks like this:
Target directory structure
SubDirAA combined directories SubDirAB combined directories SubDirAC combined directories SubDirBC combined directories
So the sub directories in DirA will be combined with like-named sub directories in DirB and they will move up a level in the hierarchy.
|
Untested:
use warnings;
use strict;
use File::Find;
use File::Copy;
use File::Path;
use File::Spec;
my @dirs = qw( DirA DirB );
for my $dir ( @dirs ) {
find( sub {
my @paths = File::Spec->splitdir( $File::Find::dir );
for my $i ( 0 .. $#paths ) {
if ( $path[$i] eq $dir ) {
splice @paths, $i, 1;
last;
}
}
my $new_dir = File::Spec->catdir( @paths );
mkpath( $new_dir ) unless -d $newdir;
if ( -e "$newdir/$_" ) {
warn "$newdir/$_ already exists, cannot copy!n";
}
else {
copy( $_, "$newdir/$_" );
}
}, $dir );
}
QUOTE |
I have the following script for combining txt files in a directory but I don't know the Perl syntax well enough to apply it to combining directories (if I can modify this script for that purpose). I've done an extensive web search but haven't found much that helps. Can someone point me in the right direction?
#!perl use warnings;
for my $f ( map "lv$_.txt", 1..960) { for ( grep -f, map $_.$f, qw( a/ b/ c/ d/ e/)) { $f2 = $_;
open STDIN, $_; open STDOUT, ">>$f";
while( <STDIN> ) { unless($_ =~ /username/ ) { print STDOUT "$_"; }elsif ($f2 =~ /a/ ) { print STDOUT "$_"; } } } }
This is a great script
|
It doesn't look THAT great. You try to open the files without verifying that
they have in fact opened correctly. You use STDIN and STDOUT instead of
defining your own filehandles. You unnecessarily put scalars in quotes.
QUOTE |
that I believe I got from one of you listers.
|
Was that me? I believe I posted something like:
#!/usr/bin/perl
use warnings;
use strict;
for my $f ( map "LV$_.txt", 1 .. 960 ) {
for( grep -f, map "$_/$f", qw( a b c d ) ) {
open IN, $_;
open OUT, ">>$f";
while ( <IN> ) {
next if $. == 1 and -s OUT;
print OUT;
}
close IN;
}
}
If that was me, I apologise for the bad example!
John
--
use Perl;
program
fulfillment
John W. Krahn
Apr 6 2005, 09:11 PM
John W. Krahn wrote:
QUOTE |
Debbie Cooper wrote:
I have the following script for combining txt files in a directory but I don't know the Perl syntax well enough to apply it to combining directories (if I can modify this script for that purpose). I've done an extensive web search but haven't found much that helps. Can someone point me in the right direction?
#!perl use warnings;
for my $f ( map "lv$_.txt", 1..960) { for ( grep -f, map $_.$f, qw( a/ b/ c/ d/ e/)) { $f2 = $_;
open STDIN, $_; open STDOUT, ">>$f";
while( <STDIN> ) { unless($_ =~ /username/ ) { print STDOUT "$_"; }elsif ($f2 =~ /a/ ) { print STDOUT "$_"; } } } }
This is a great script
It doesn't look THAT great. You try to open the files without verifying that they have in fact opened correctly. You use STDIN and STDOUT instead of defining your own filehandles. You unnecessarily put scalars in quotes.
that I believe I got from one of you listers.
Was that me? I believe I posted something like:
#!/usr/bin/perl use warnings; use strict;
for my $f ( map "LV$_.txt", 1 .. 960 ) { for( grep -f, map "$_/$f", qw( a b c d ) ) { open IN, $_; open OUT, ">>$f"; while ( <IN> ) { next if $. == 1 and -s OUT; print OUT; } close IN; } }
If that was me, I apologise for the bad example!
|
I dug up my old email and what I actually posted was:
#!perl
use warnings;
use strict;
for my $f ( map "LV$_.txt", 1 .. 960 ) {
for ( grep -f, map "$_/$f", qw( a b c d ) ) {
open IN, $_ or die $!;
open OUT, ">>$f" or die $!;
while ( <IN> ) {
next if $. == 1 and -s OUT;
print OUT;
}
close OUT;
close IN;
}
}
__END__
So it wasn't that bad of an example.
John
--
use Perl;
program
fulfillment
JupiterHost.Net
Apr 6 2005, 09:21 PM
QUOTE |
So the sub directories in DirA will be combined with like-named sub directories in DirB and they will move up a level in the hierarchy.
Untested:
|
Why not use File::Copy::Recursive's dircopy() it has been tested and its
simpler (to develop code and maintain it later or if you inherit the job) :)
use strict;
use warnings;
use File::Copy::Recursive 'dircopy';
my $target = shift @ARGV;
dircopy($_,$target) or warn "$target -> $_ : $!" for @ARGV;
now you can
../myrsync.pl target DirA DirB DirC /etc
or just rsync like was also mentioned
QUOTE |
use warnings; use strict; use File::Find; use File::Copy; use File::Path; use File::Spec;
my @dirs = qw( DirA DirB );
for my $dir ( @dirs ) { find( sub { my @paths = File::Spec->splitdir( $File::Find::dir ); for my $i ( 0 .. $#paths ) { if ( $path[$i] eq $dir ) { splice @paths, $i, 1; last; } } my $new_dir = File::Spec->catdir( @paths ); mkpath( $new_dir ) unless -d $newdir; if ( -e "$newdir/$_" ) { warn "$newdir/$_ already exists, cannot copy!n"; } else { copy( $_, "$newdir/$_" ); } }, $dir ); } |
John Moon
Apr 7 2005, 02:25 PM
I have a function which prints array:
sub print_array {
my $array_ref = shift;
for(@$array_ref){
print "$_n";
}
}
And I have a big array, for example named @array.
I want to print @array elements from N to N+100 using this function, but
don't want to use second array (they are can be very big). After print I
don't need @array anymore.
I do this:
$#array = $N+100;
print_array($array[$N]);
But I got error: [Not an ARRAY reference at ... ]
Is ARRAY reference in perl not the reference to the first element of ARRAY ?
Or is the better way to solve this problem?
Please note that $array[$N] is a scalar...
Also you are expecting an array reference in your sub but not calling with a
reference...
Here is another way...
perl -e '@a=(1 .. 500); $from=0; $cnt= 5;&print_array(@a,$from, $from +
$cnt);sub print_array{ ($list,$from, $to)=@_; print $$list[$from - 1], "n"
while (++$from <= $to) ;}'
Ambikesh Chaurasia
Apr 11 2005, 12:14 AM
Hi Jose,
Thanks for your suggetion. I already tried this erlier
and once again.
It does not work. I tried following example. Any other
suggestions.
------------------
#include <stdio.h>
int main()
{
printf"Returning 100n";
return 100;
}
------------------
$gcc ret_100.c
-------------------------
#!/usr/bin/perl -w
my $ret_val = `./a.out`;
print "AC::", $ret_val, "n";
--------------------------
Thanks and regards
Ambikesh
--- Jose Nyimi <[Email Removed]> wrote:
QUOTE |
-----Message d'origine----- De : Ambikesh Chaurasia [mailto:[Email Removed]] Envoy : dimanche 10 avril 2005 18:30 : perl Objet : Capturing the integer return value of a "C" program, called inside perl script
Hi Guys,
I want to capture the return value of a "C" program called inside a perl script. How to do this??
Let say I have a "C" program named "val_100.c" .
//val_100.c #include <stdio.h int main() { return 100; }
I want to call this program from a perl script and want to store the return value "100" in the perl script. (Please note that I do not want to capture the running status of the program).
Please guide me how to do this in a perl script.
perldoc -q backticks
my $ret_val = `c_prog_call`;
HTH, Jos.
|
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
David Gilden
Apr 13 2005, 03:15 PM
Greetings,
Thanks for the help so far,
I am added switch... but not sure that I have syntax correct....
Maybe this is best written as if else logic....
and or:
my $action = $q->param( "action" );
SWITCH ($action) {
if (/Upload/) {
last SWITCH;
};
etc.......
--- what I have now----
use CGI qw/:standard/;
use CGI;
use Fcntl qw( :DEFAULT :flock );
use CGI::Carp qw(fatalsToBrowser);
use strict;
use switch;
my $action = $q->param( "action" );
SWITCH: {
if ($action =~ /Upload/) {
last SWITCH;
};
if ($action =~ /Update/) {
print redirect("./import_clean_csv.php");
exit;
last SWITCH;
};
if ($action =~ /Clean/) {
my @filesToRemove;
chdir UPLOAD_DIR or die "Couldn't chdir to afm_data directory: $!";
#my @filesToRemove = map {$_ =~ /^(w[w.-]*)/} <*>;
opendir(DR,"./");
@filesToRemove = grep {$_ =~ /^(w[w.-]*)/} readdir DR;
closedir DR;
print $HTML_HEADER;
print '<div align="center">';
foreach my $fr (@filesToRemove) {
print "Deleted $fr<br>n";
unlink($fr) or die "Couldn't Delete $fr $!";
}
print <<HTML_OUT;
<p class="top-header">Your Done close this window!
<form><input type="button" onclick="self.close()" value="Close Window"></form></p>
</div>
HTML_OUT
print end_html;
exit;
last SWITCH;
};
}
David Gilden
Apr 14 2005, 12:44 AM
Dear Perl Gurus,
I have some problems that I think are a result of how my Switch statement is written.
This script is invoked via a web browser to upload a file, and do a few other things.
However it appears that the user system / network, or my script is stalling. So
the user clicks the button a second and a third time before the script has
finished. The system admin has made me aware that this script is maxing out the
CPU usage of server. He is not happy....
I thought have surrounding a portion of the code and putting in an if
block ...
if (!$state) {
do lots of stuff related to file upload...
}
$state could be read and written to and store a 0 for ready to do something,
or a 1 for, 'busy now, don't brother me'......
Another issue to improve the performance of the script
was to move stuff inside a switch block, but I am not sure how this would
impact scope :
SWITCH: {
if ($action =~ /Upload/) {
use Fcntl qw( :DEFAULT :flock );
use constant MAX_FILE_SIZE => 2 * 1_048_576; # Limit each upload to 2 MB
use constant MAX_DIR_SIZE => 10 * 1_048_576; # Limit total uploads to 10 MB
use constant MAX_OPEN_TRIES => 100;
last SWITCH;
};
--
if ($action =~ /AnotherCmd/) {
### is order backwards on these next two lines?
exit;
last SWITCH;
}
Could some comment on using Switch or Case statements vers If {} else blocks
Thanks...
Dave Gilden
PS: I am not sure of syntax that I should be using for Switch I have seen several variants
as I have read documentation today....
--- what I have now----
use CGI qw/:standard/;
use CGI;
use Fcntl qw( :DEFAULT :flock );
use CGI::Carp qw(fatalsToBrowser);
use strict;
use switch;
my $action = $q->param( "action" );
SWITCH: {
if ($action =~ /Upload/) {
last SWITCH;
};
if ($action =~ /Update/) {
print redirect("./import_clean_csv.php");
exit;
last SWITCH;
};
if ($action =~ /Clean/) {
my @filesToRemove;
chdir UPLOAD_DIR or die "Couldn't chdir to _data directory: $!";
opendir(DR,"./");
@filesToRemove = grep {$_ =~ /^(w[w.-]*)/} readdir DR;
closedir DR;
print $HTML_HEADER;
print '<div align="center">';
foreach my $fr (@filesToRemove) {
print "Deleted $fr<br>n";
unlink($fr) or die "Couldn't Delete $fr $!";
}
print <<HTML_OUT;
<p class="top-header">Your Done close this window!
<form><input type="button" onclick="self.close()" value="Close Window"></form></p>
</div>
HTML_OUT
print end_html;
exit;
last SWITCH;
};
}
#more....
__END__
Offer Kaye
Apr 14 2005, 05:00 AM
On 4/14/05, David Gilden wrote:
Where is "use warnings;" ? It seems to be missing ;-)
Shouldn't that be "use Switch;" (with a capital "S")?
Read "perldoc Switch", the usage syntax is well documented there.
--
Offer Kaye