Re: Can't call method error

2011-08-12 Thread Uri Guttman
> "FH" == Feng He writes: FH> You will always be able to check the return status of a method call, FH> something like: FH> my $obj = Some::Module->new FH> or die "can't create object from Some::Module"; please learn to bottom post. i now have to comment on your answer and also

Re: Just why?

2011-08-12 Thread Uri Guttman
> "OL" == Olga Lee writes: OL> Oh, thank you!! OL> Now I understand, the point is that if don't suppose to give an OL> argument to function, i should declare it as function() with brackets. that is actually the wrong point. don't use prototypes unless there is a major benefit to using

Re: Can't call method error

2011-08-12 Thread Feng He
You will always be able to check the return status of a method call, something like: my $obj = Some::Module->new or die "can't create object from Some::Module"; Regards. On Sat, Aug 13, 2011 at 7:58 AM, Jeffrey Joh wrote: > > I'd like to include code so that if I get the following error

Can't call method error

2011-08-12 Thread Jeffrey Joh
I'd like to include code so that if I get the following error, the script will just ignore it and keep running: "Can't call method "attr" on an undefined value at abcde.pl line 2" Does anyone know of such a code? Jeff -- To unsubscribe, e-mail: be

Re: How to grab last element of array from split with no temporary variables?

2011-08-12 Thread John W. Krahn
Randal L. Schwartz wrote: "John" == "John W Krahn" writes: John> split() uses @_ by default so you could just say: That's deprecated though, if not already gone. (Looks gone in Perl 5.14.) It was a readily-admitted misfeature. Unless you're playing golf. :-) John -- Any intelligent f

Re: Just why?

2011-08-12 Thread Olga Lee
Oh, thank you!! Now I understand, the point is that if don't suppose to give an argument to function, i should declare it as function() with brackets. Thanks again! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.pe

Re: How to grab last element of array from split with no temporary variables?

2011-08-12 Thread Randal L. Schwartz
> "John" == "John W Krahn" writes: John> split() uses @_ by default so you could just say: That's deprecated though, if not already gone. (Looks gone in Perl 5.14.) It was a readily-admitted misfeature. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 http:/

Re: while(@data) works but why

2011-08-12 Thread Tony Esposito
It was the absence of the 'use strict;' that permitted the execution. Now fails if 'use strict;' is added to code and 'my' is missing. Added 'use strict;' and 'my'. Cheers! From: Jim Gibson To: beginners@perl.org Sent: Fri, 12 August, 2011 14:13:26 Subject: Re

Re: while(@data) works but why

2011-08-12 Thread Tony Esposito
got it ... thank you. cheers! From: Brandon McCaig To: Tony Esposito Cc: beginners@perl.org Sent: Fri, 12 August, 2011 14:08:52 Subject: Re: while(@data) works but why On Fri, Aug 12, 2011 at 3:02 PM, Tony Esposito wrote: > . > . > . > while(@dat = $sth->fe

Re: while(@data) works but why

2011-08-12 Thread Jim Gibson
On 8/12/11 Fri Aug 12, 2011 12:02 PM, "Tony Esposito" scribbled: > . > . > . > while(@dat = $sth->fetchrow) { > print "@dat\n"; > . > . > . > > This code works yet there is no 'my @dat' defined anywhere in the code. > Using Perl 5.8.x - 5.14.x > > Q: Why does the variable @dat not nee

Re: while(@data) works but why

2011-08-12 Thread Brandon McCaig
On Fri, Aug 12, 2011 at 3:02 PM, Tony Esposito wrote: > . > . > . > while(@dat = $sth->fetchrow) { >        print "@dat\n"; > . > . > . > > This code works yet there is no 'my @dat' defined anywhere in the code. > Using Perl 5.8.x - 5.14.x > > Q: Why does the variable @dat not need a 'my' in front

while(@data) works but why

2011-08-12 Thread Tony Esposito
. . . while(@dat = $sth->fetchrow) { print "@dat\n"; . . . This code works yet there is no 'my @dat' defined anywhere in the code. Using Perl 5.8.x - 5.14.x Q: Why does the variable @dat not need a 'my' in front? Cheers!

Re: Just why?

2011-08-12 Thread Shawn H Corey
On 12/08/11 02:22 PM, Robert Wohlfarth wrote: On Fri, Aug 12, 2011 at 7:03 AM, TimKapHwan wrote: #!/usr/bin/perl -w sub func { return 10; } print func * 5, "\n"; Perl interprets that command like this: print func(*5, "\n"); The "*5" and "\n" become parameters to func. Change the code like

Re: Just why?

2011-08-12 Thread Robert Wohlfarth
On Fri, Aug 12, 2011 at 7:03 AM, TimKapHwan wrote: > #!/usr/bin/perl -w > sub func > { > return 10; > } > print func * 5, "\n"; > Perl interprets that command like this: print func(*5, "\n"); The "*5" and "\n" become parameters to func. Change the code like this: print func() * 5, "\n"; -- Ro

Re: Just why?

2011-08-12 Thread Shawn H Corey
On 12/08/11 08:03 AM, TimKapHwan wrote: Hello all! My first question in this group =) Can someone explain me why this work fine: #!/usr/bin/perl -w sub func { return 10; } print 5 * func, "\n"; The answer is 50. Good! But then i change func and 5: #!/usr/bin/perl -w sub func { return 10;

Re: How to grab last element of array from split with no temporary variables?

2011-08-12 Thread Rob Dixon
On 12/08/2011 18:52, Rob Dixon wrote: > On 12/08/2011 00:17, siegfr...@heintze.com wrote: >> This works! Is there a way to do it with less typing? How can I do it >> without creating a temporary variable "@p"? >> Thanks, >> siegfried >> >> find /xyz -exec perl -e 'foreach(@ARGV){ my @p=split "/"; r

Just why?

2011-08-12 Thread TimKapHwan
Hello all! My first question in this group =) Can someone explain me why this work fine: #!/usr/bin/perl -w sub func { return 10; } print 5 * func, "\n"; The answer is 50. Good! But then i change func and 5: #!/usr/bin/perl -w sub func { return 10; } print func * 5, "\n"; The output is 10 Wi

Re: How to grab last element of array from split with no temporary variables?

2011-08-12 Thread Rob Dixon
On 12/08/2011 00:17, siegfr...@heintze.com wrote: This works! Is there a way to do it with less typing? How can I do it without creating a temporary variable "@p"? Thanks, siegfried find /xyz -exec perl -e 'foreach(@ARGV){ my @p=split "/"; rename $_, "./$p[$#p].txt" } ' find /xyz -exec perl -e

Re: How to grab last element of array from split with no temporary variables?

2011-08-12 Thread Brandon McCaig
On Thu, Aug 11, 2011 at 7:17 PM, wrote: > find /xyz -exec perl -e 'foreach(@ARGV){ my @p=split "/"; rename $_, > "./$p[$#p].txt" } ' If I'm reading this right then it looks like you're trying to recursively move all files in /xyz into the current directory. Probably don't need Perl for that. fi