Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: SoundOff Program (eg. for Pandora Radio)

by jwkrahn (Monsignor)
on Dec 05, 2011 at 04:19 UTC ( #941786=note: print w/replies, xml ) Need Help??


in reply to SoundOff Program (eg. for Pandora Radio)

my $xpm = qq{ :/* XPM */ :static char *xpm[] = $lb :"$w $h $nsyms 1", }; # Fill in XPM color symbols foreach my $key (keys %$h_xpm) { my $line = sprintf "%s c %s", $key, $h_xpm->{$key}; $xpm .= qq{\n\t\t:"$line",}; } $xpm =~ s/(^\s+:)|((?<=\n)\s+:)|(\s+$)//g;

Why add the leading whitespace and colon when you are just going to remove them anyway?

And the substitution would be more efficient as:

$xpm =~ s/^\s+://mg; $xpm =~ s/\s+$//;

Or at least don't use unneeded capturing parentheses:

$xpm =~ s/(?:^\s+:)|(?:(?<=\n)\s+:)|(?:\s+$)//g;

Replies are listed 'Best First'.
Re^2: SoundOff Program (eg. for Pandora Radio)
by liverpole (Monsignor) on Dec 05, 2011 at 13:07 UTC
        Why add the leading whitespace and colon when you are just going to remove them anyway?

    Because it's far more easy to visually parse when it's indented, and I use that formatting trick in other programs, where I sometimes have to hand-edit the text, and it's much easier when the line begins with ':' than without.

        And the substitution would be more efficient as..."

    So what? It's in the startup code so it's not a performance hit, and I think the "unneeded" capturing parentheses makes it easier to read. But, yeah, thanks for "enlightening" me on regular expressions.

    Honestly, I posted this because I thought it might be useful to a few others besides me, not because I needed the code nit-picked for insignificant optimization. Did you even run it? Or was this just a chance to show off your ikegami-like superiority? It's your type of comments that make me tired and sad that I even post here any more.


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2021-11-27 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?