Hello again,

In effect some special variable can be aliased and still works properly ( as $" for example ) and others cannot ( as $\ and $1 ):

use strict; use warnings; print $/.'aliasing output record separator. $\\'."\n"; for $\ (qw( a b )) { # this does not works print "\$\\ is ->$\<- but is not appended\n"; } print $/.'aliasing output list separator $"'."\n"; for $" (qw( a b )) { # $" is aliased to a then b,c.. # BUT is still the output list separator print "@{[1, 2, 3]}\n"; } print $/.'aliasing eval error $@'."\n"; for $@ (qw( a b )) { print "now \$@ is: $@\n"; # no need to localize $@ eval '2 / 0'; print "then \$@ is: $@"; } print $/.'aliasing first captured match $1'."\n"; for $1 (qw( a b )) { print "now \$1 is: $1\n"; 'XXX' =~ /(.)/; print "then \$1 is WRONG after a match: $1\n"; { local $1; if ('YYYY' =~ /(.)/){ print "then \$1 is wrong even if \$1 is localized: ".( +$1 ? $1 : 'UNDEF')."\n"; } } } my $text =<<EOT; first second SEP fourth SEP last EOT print $/.'input record separator $/'."\n"; for $/ (qw( \n SEP )) { print "now \$/ is: $/\n"; print "LINE:->$_<-\n" for split $/,$text; } #OUTPUT aliasing output record separator. $\ $\ is ->a<- but is not appended $\ is ->b<- but is not appended aliasing output list separator $" 1a2a3 1b2b3 aliasing eval error $@ now $@ is: a then $@ is: Illegal division by zero at (eval 1) line 1. now $@ is: b then $@ is: Illegal division by zero at (eval 2) line 1. aliasing first captured match $1 now $1 is: a then $1 is WRONG after a match: a then $1 is wrong even if $1 is localized: UNDEF now $1 is: b then $1 is WRONG after a match: b then $1 is wrong even if $1 is localized: UNDEF input record separator $/ now $/ is: \n LINE:->first<- LINE:->second<- LINE:->SEP<- LINE:->fourth<- LINE:->SEP<- LINE:->last<- now $/ is: SEP LINE:->first second <- LINE:-> fourth <- LINE:-> last <-

L*

PS anyway we all know is a stupid thing to do ;)

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re^9: foreach $1 -- all special variables by Discipulus
in thread foreach $1 by choroba

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.