Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Re: Re: Why do we say the =~ operator "binds"?

by emazep (Priest)
on Apr 19, 2004 at 05:55 UTC ( #346198=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Why do we say the =~ operator "binds"?
in thread Why do we say the =~ operator "binds"?

Well, I not only wouldn't use explicit loop variables when I can resort to the singular pronoun (or even better, when I can omit it) but I would also try to avoid unnecessary assignments ;-)
foreach (@email_addresses) { if ( /[a-zA-Z0-0.]+\@[a-zA-Z0-0.]+/ ) { .... } }
This is IMHO more legible, as long as your public is fluent in Perl, or just knows the basics.
The only context where I would use your code is a Perl class, but just to show immediately after how to shorten that code and make it more legible (confess, you are a teacher! ;-)

Cheers,
Emanuele.

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Why do we say the =~ operator "binds"?
by William G. Davis (Friar) on Apr 20, 2004 at 04:48 UTC

    Emazep, it was just an example; Diotalevi and I were talking about a situation in which the assignment is practical for some reason (like if you're calling m//g in scalar context), not one where you can get away with sticking m// in a conditional by itself. (Who on earth would store away the result unless they needed for something later on, anyway?)

    My point was that if you have an assignment like "$var = /pattern/", then name the variables and use the binding operator explicitly so it's completely unambiguous: "$pos = $string =~ /pattern/g".

    In real life I would have written that validity checking code like this:

    foreach my $address (@email_addresses) { return unless ($address =~ /[a-zA-Z0-0.]+\@[a-zA-Z0-0.]+/); # proceed normally...
      I apologize for my (pointless) excess of pedantry.

      Cheers,
      Emanuele.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://346198]
help
Chatterbox?
[stevieb]: man, when the roads are glare ice, I don't even bother going to work or out... unless I absolutely have to, or was already out in the first place
[choroba]: Tire chains are mandatory here in mountains, and the only unprepared each year are gritters
[stevieb]: I have a 3 day winter survival kit in my vehicle in the event I get snowed in in the mountains (which has happened before due to avalanches closing the roads (and once in the summer due to a massive forest fire that trapped us
[perldigious]: a handful of people in my work area did not make it, but I live pretty close and it's flat the whole way, so I didn't have any trouble. The roundabout is the worst thing I have to negotiate.
[thezip]: G'day all!
[perldigious]: Well, that and dodging the people who forget how ice works right away. :-)
[stevieb]: hey, thezip
[perldigious]: I don't miss having to drive up and down in elevation on roads that are iced over, I white knuckled gripping the steering wheel every time I had to where I used to live.
[perldigious]: So I don't envy you mountain guys if you have to drive in the winter, even with tire chains.
MidLifeXis waves.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2016-12-06 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.