Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: What is this line doing in the perl script?

by Corion (Pope)
on Aug 25, 2010 at 07:48 UTC ( #857104=note: print w/replies, xml ) Need Help??


in reply to What is this line doing in the perl script?

You haven't told us what part of the line you have problems understanding.

You can learn what the line is doing from perlre about the /g flag, and from perlsyn about what the assignment does.

Maybe it helps you to look at this example:

use strict; use Data::Dumper; my @list = ("abcdef" = /(.)./g); print Dumper \@list; (my ($first)) = @list; print "$first\n"; # in one step (my $first) = ("abcdef" = /(.)./g);

Replies are listed 'Best First'.
Re^2: What is this line doing in the perl script?
by codeacrobat (Chaplain) on Aug 25, 2010 at 18:54 UTC
    You are missing the tilde in the match.
    Should've been:
    use strict; use Data::Dumper; my @list = ("abcdef" =~ /(.)./g); print Dumper \@list; (my ($first)) = @list; print "$first\n"; # in one step (my $first) = ("abcdef" =~ /(.)./g);

    print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://857104]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (None)
    As of 2021-10-16 03:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My first memorable Perl project was:







      Results (69 votes). Check out past polls.

      Notices?