Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
It's not easy to understand what your question is, that's why you get fuzzy answers.

> I guess that perl tried to interpret $1[ as element of an array @1?

yes

@1=a..c; my $a="012210"; $a =~ s/(.)/$1[$1]/g; print $a;

abccba

> So I solved this problem in two ways, using ...

Excellent you even solved it, so what is the question again? :)

Your title $1[ is - sorry - really crap, please see How do I compose an effective node title? for inspiration.

And your question is obscured in between lots of regex line noise, please see How do I post a question effectively?

Now the gory details ...

you said in one of your replies

> which looks to me as a bug.

nope, but IMHO it's ...

... flawed by concept:

Normally an identifier in Perl has to match something like /[_a-zA-Z^][_a-zA-Z0-9]*/ but special variables like $\ or $1 are exceptions (see perlvar#SPECIAL-VARIABLES for a list)

They are global symbols and don't need to be declared.

Unfortunately this covers other possible slots of such a symbol, like %hash, @array, $scalar, &code, *glob and probably also filehandle and format....

(see perlmod#Symbol-Tables and perlref#Making-References point 7 for details)

For instance %\ doesn't have any meaning, but since $\ is a special variable, it is

  • legally parsed and
  • globally available.

I'd rather prefer that undefined special vars fail under strict, alas, we are talking about a language which supported this concept already in Perl4, i.e. long before it introduced lexicals and strict.

Not a bug

Since this /$array[/ is a parsing error and since 1 is not less a symbol than array it's not a bug.

This is normally not a problem, but regex' tend to become messy.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!


In reply to Re: $1[ (or "Does an array @1 exist in Perl ? - Yes!") by LanX
in thread $1[ by rsFalse

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-16 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found