Re: initialising a list of variables
And the clouds parted, and Rob Dixon said... Gary Stainburn wrote: SNIP! Hi Gary. Just one more offering: $_ = '' foreach my ($fred, $ginger); HTH, Rob ...and in the spirit of TMTOWTDI... map {$_=} my ($fred, $ginger); :) /~~\ | Brian Gerard Do not taunt Happy Fun Ball.| | First initial + 'lists'| | at technobrat dot com | \__/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: initialising a list of variables
Gary Stainburn wrote: I've got a query about variable initialisation. I want to initialise a list of variables to an empty string, but I'm having troubles. What's the best wat to do this? If I use the following I get: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; my $fred=$ginger=''; print fred=$fred\n; print ginger=$ginger\n; [EMAIL PROTECTED] gary]$ ./t Global symbol $ginger requires explicit package name at ./t line 5. Global symbol $ginger requires explicit package name at ./t line 8. Execution of ./t aborted due to compilation errors. [EMAIL PROTECTED] gary]$ but if I use: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; my ($fred,$ginger)=''; print fred=$fred\n; print ginger=$ginger\n; [EMAIL PROTECTED] gary]$ ./t fred= Use of uninitialized value in concatenation (.) or string at ./t line 8. ginger= [EMAIL PROTECTED] gary]$ Hi Gary. Just one more offering: $_ = '' foreach my ($fred, $ginger); HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: initialising a list of variables
From: Gary Stainburn [EMAIL PROTECTED] I've got a query about variable initialisation. I want to initialise a list of variables to an empty string, but I'm having troubles. What's the best wat to do this? If I use the following I get: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; use warnings; no warnings 'uninitialized'; my ( $fred, $ginger); The uninitialized warning is IMHO useless and annoying. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
initialising a list of variables
Hi folks I've got a query about variable initialisation. I want to initialise a list of variables to an empty string, but I'm having troubles. What's the best wat to do this? If I use the following I get: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; my $fred=$ginger=''; print fred=$fred\n; print ginger=$ginger\n; [EMAIL PROTECTED] gary]$ ./t Global symbol $ginger requires explicit package name at ./t line 5. Global symbol $ginger requires explicit package name at ./t line 8. Execution of ./t aborted due to compilation errors. [EMAIL PROTECTED] gary]$ but if I use: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; my ($fred,$ginger)=''; print fred=$fred\n; print ginger=$ginger\n; [EMAIL PROTECTED] gary]$ ./t fred= Use of uninitialized value in concatenation (.) or string at ./t line 8. ginger= [EMAIL PROTECTED] gary]$ -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: initialising a list of variables
but if I use: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; my ($fred,$ginger)=''; print fred=$fred\n; print ginger=$ginger\n; [EMAIL PROTECTED] gary]$ ./t fred= Use of uninitialized value in concatenation (.) or string at ./t line 8. ginger= [EMAIL PROTECTED] gary]$ my ($fred, $ginger) = ('') x 2; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: initialising a list of variables
On Friday, October 3, 2003, at 09:55 AM, Gary Stainburn wrote: Hi folks Howdy. I've got a query about variable initialisation. I want to initialise a list of variables to an empty string, but I'm having troubles. What's the best wat to do this? How about: my($fred, $ginger) = ('') x 2; James If I use the following I get: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; my $fred=$ginger=''; print fred=$fred\n; print ginger=$ginger\n; [EMAIL PROTECTED] gary]$ ./t Global symbol $ginger requires explicit package name at ./t line 5. Global symbol $ginger requires explicit package name at ./t line 8. Execution of ./t aborted due to compilation errors. [EMAIL PROTECTED] gary]$ but if I use: [EMAIL PROTECTED] gary]$ cat t #!/usr/bin/perl -w use strict; my ($fred,$ginger)=''; print fred=$fred\n; print ginger=$ginger\n; [EMAIL PROTECTED] gary]$ ./t fred= Use of uninitialized value in concatenation (.) or string at ./t line 8. ginger= [EMAIL PROTECTED] gary]$ -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: initialising a list of variables
my $fred=$ginger=''; Should be: my $fred = my $ginger = ''; my ($fred,$ginger)=''; Should be: my ($fred,$ginger) = ('',''); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: initialising a list of variables
On Friday 03 Oct 2003 4:05 pm, James Edward Gray II wrote: On Friday, October 3, 2003, at 09:55 AM, Gary Stainburn wrote: Hi folks Howdy. I've got a query about variable initialisation. I want to initialise a list of variables to an empty string, but I'm having troubles. What's the best wat to do this? How about: my($fred, $ginger) = ('') x 2; Hmmm, thanks you three for this. However, while I can see why - one array initialised by another array of the same size - I'd have expected a simpler method from Perl. It's open to user error quite easily by not specifying enough on the right side, and Perl's usually better at making life easy for the programmer. Or is it just that I'm getting too spoilt by Perl? James [snip] -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: initialising a list of variables
It's open to user error quite easily You can also use this... my $x = my $y = ''; ...Or... my ($x, $y); $x = $y = ''; ...Or... init(my ($x,$y)); sub init { $_ = '' for (@_); } This last one uses the fact that $_ is an alias to the array item in @_, and @_ contains aliases to the variables that were passed. So modifying $_ modified $x and $y directly without having to return a value. Rob -Original Message- From: Gary Stainburn [mailto:[EMAIL PROTECTED] Sent: Friday, October 03, 2003 11:27 AM To: James Edward Gray II Cc: [EMAIL PROTECTED] Subject: Re: initialising a list of variables On Friday 03 Oct 2003 4:05 pm, James Edward Gray II wrote: On Friday, October 3, 2003, at 09:55 AM, Gary Stainburn wrote: Hi folks Howdy. I've got a query about variable initialisation. I want to initialise a list of variables to an empty string, but I'm having troubles. What's the best wat to do this? How about: my($fred, $ginger) = ('') x 2; Hmmm, thanks you three for this. However, while I can see why - one array initialised by another array of the same size - I'd have expected a simpler method from Perl. It's open to user error quite easily by not specifying enough on the right side, and Perl's usually better at making life easy for the programmer. Or is it just that I'm getting too spoilt by Perl? James [snip] -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]