|
From: Ch Lamprecht on 21 Sep 2006 03:57 Tad McClellan wrote: > David Squire <David.Squire(a)no.spam.from.here.au> wrote: > >>ed wrote: > > >>> my %h = %_; >> >>Hmmm. Is there such a variable s %_? > > > > Yes there is. (but it doesn't do anything for the OP.) > > There is a $_ variable, so then there is also @_ and %_ (and > a few more) variables. > > > eg: Since there is a $@ variable, this works fine, even with strictures: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ perlvar: Perl identifiers that begin with digits, control characters, or punctuation characters are exempt from the effects of the package declaration and are always forced to be in package main; they are also exempt from strict 'vars' errors. > > ----------------- > #!/usr/bin/perl > use warnings; > use strict; > > @@ = qw/foo bar/; > print "$_\n" for @@; > > %@ = qw/foo FOO bar BAR/; > print "$_ => $@{$_}\n" for keys %@; > ----------------- > > so this will work with any variable name starting with a control character: use warnings; use strict; @? = qw/foo bar/; print "$_\n" for @?; %? = qw/foo FOO bar BAR/; print "$_ => $?{$_}\n" for keys (%?); Christoph -- perl -e "print scalar reverse q/ed.enilno(a)ergn.l.hc/"
From: Dr.Ruud on 21 Sep 2006 04:13 Ch Lamprecht schreef: > so this will work with any variable name starting with a > control character: > > use warnings; > use strict; > > @? = qw/foo bar/; > print "$_\n" for @?; > > %? = qw/foo FOO bar BAR/; > print "$_ => $?{$_}\n" for keys (%?); I see no "variable name starting with a control character" in your example. -- Affijn, Ruud "Gewoon is een tijger."
From: Ch Lamprecht on 21 Sep 2006 04:55 Dr.Ruud wrote: > Ch Lamprecht schreef: > > >>so this will work with any variable name starting with a >>control character: >> >>use warnings; >>use strict; >> >>@? = qw/foo bar/; >>print "$_\n" for @?; >> >>%? = qw/foo FOO bar BAR/; >>print "$_ => $?{$_}\n" for keys (%?); > > > I see no "variable name starting with a > control character" in your example. > Of course you are right. s/control/punctuation/ -- perl -e "print scalar reverse q/ed.enilno(a)ergn.l.hc/"
From: ed on 21 Sep 2006 14:27 On Wed, 20 Sep 2006 22:31:53 GMT "John W. Krahn" <someone(a)example.com> wrote: > ed wrote: > > I'm having a bit of trouble sending hash elements to sub routines > > and back. > > > > Any help appreciated! > > > > sub entry { > > my $l = shift; > > my %h = %_; > > > > while( ( my $k, my $v ) = each ( %h ) ) { > > print( "K: $k V: $v\n" ); > > } > > return(%h); > > } > > > > $h{'stuff'} = "hello"; > > %h = entry( "1", \%h ); > > > > When run %h becomes empty in entry. > > You are calling entry() with a hash reference so you have to > dereference it inside the sub: > > sub entry { > my $l = shift; > my $h = shift; > > while( my ( $k, $v ) = each ( %$h ) ) { > print( "K: $k V: $v\n" ); > } > return %h; > } Thank you all very much, Abigail, David and Tad. Problem solved. This was a very difficult problem for me, I would never have solved it alone. -- Regards, Ed :: http://www.linuxwarez.co.uk proud bash person When Chuck Norris roundhouse kicks people, they do not die of blunt trauma or tissue damage. They simple lose their will to live.
First
|
Prev
|
Pages: 1 2 Prev: Use of uninitialized value in print Next: Tk-perl2exe FileSelect error |