Code Comments
Programming Forum and web based access to our favorite programming groups.Is this how the pros would do this? $ perl -we 'print join ",", map($_*10,(1..10))' 10,20,30,40,50,60,70,80,90,100 Simpler ways would get an extra comma, or be meant for non gappy lists.
Post Follow-up to this message* Dan Jacobson schrieb: > Is this how the pros would do this? > $ perl -we 'print join ",", map($_*10,(1..10))' > 10,20,30,40,50,60,70,80,90,100 > Simpler ways would get an extra comma, or be meant for non gappy lists. You could get rid of all those needless parentheses to shorten your line a little bit. $ perl -we'print+join",",map$_*10,1..10' Alternatively, you could use grep() instead of map(). Sure, You need the same number of characters to type -- it's just another way to doing the same thing (remember, TIMTOWTDI ;-). $ perl -we'print+join",",grep/0/,1..100' But I think this is not as efficient as your first thought. My last idea is to set $OUTPUT_FIELD_SEPARATOR (»$,«, look into `perldoc perlvar` for details) to a suitable value, to save one more character ;-) $ perl -we'$,=",";print+map$_*10,1..10' $ perl -we'$,=",";print+grep/0/,1..100' regards, fabian
Post Follow-up to this messageOn Wed, 27 Apr 2005, Dan Jacobson wrote: > Is this how the pros would do this? > $ perl -we 'print join ",", map($_*10,(1..10))' > 10,20,30,40,50,60,70,80,90,100 > Simpler ways would get an extra comma, or be meant for non gappy lists. If you're inquring about "perl golf", then the best I could do was: $ perl -e '$,="0,";print 1..10,"\b"' -- Regards, Steven
Post Follow-up to this message* Steven Kuo schrieb:
> On Wed, 27 Apr 2005, Dan Jacobson wrote:
>
>
> If you're inquring about "perl golf", then the best I could do was:
>
> $ perl -e '$,="0,";print 1..10,"\b"'
Just because my windows shell doesn't like the deleting "\b" so much and
there is no need to print out more characters than really desired:
$ perl -e 'print+join("0,",1..10),0'
But I like your idea.
regards,
fabian
Post Follow-up to this message"Dan Jacobson" <jidanni@jidanni.org> wrote in message news:877jip700r.fsf@jidanni.org... > Is this how the pros would do this? > $ perl -we 'print join ",", map($_*10,(1..10))' > 10,20,30,40,50,60,70,80,90,100 > Simpler ways would get an extra comma, or be meant for non gappy lists. Q:... when I tried to cut-n-paste it into my WIN: ActiveState I got the following Error Message, & don't know why ??? D:\study\perl\WIP>perl -we 'print join ",", map($_*10,(1..10))' Can't find string terminator "'" anywhere before EOF at -e line 1. - thanks & take care M.D. <aka> _ _ | |_ ___ _ __ ___ __ _ | |_ ___ ___ | __| / _ \ | '_ ` _ \ / _` | | __| / _ \ / _ \ | |_ | (_) | | | | | | | | (_| | | |_ | (_) | | __/ \__| \___/ |_| |_| |_| \__,_| \__| \___/ \___|
Post Follow-up to this messageMichael De Tomaso wrote: > "Dan Jacobson" <jidanni@jidanni.org> wrote in message > news:877jip700r.fsf@jidanni.org... ... ... > Q:... when I tried to cut-n-paste it into my WIN: ActiveState I got the > following Error Message, & don't know why ??? > > D:\study\perl\WIP>perl -we 'print join ",", map($_*10,(1..10))' > Can't find string terminator "'" anywhere before EOF at -e line 1. That's because the Windoze command line processor doesn't recognize ' as a quoting character, but does recognize ". Try: perl -we "print join ',',map $_*10,1..10" That is a Windoze issue, not a Perl issue, except for how it botches up Perl one-liners. > - thanks & take care M.D. ... -- Bob Walton Email: http://bwalton.com/cgi-bin/emailbob.pl
Post Follow-up to this message"Bob Walton" <see.sig@rochester.rr.com> wrote in message news:I%Bbe.8721$Bc7.4997@twister.nyroc.rr.com... > Michael De Tomaso wrote: > > ... > ... > > That's because the Windoze command line processor doesn't recognize ' as a > quoting character, but does recognize ". Try: > > perl -we "print join ',',map $_*10,1..10" > > That is a Windoze issue, not a Perl issue, except for how it botches up > Perl one-liners. > > ... > -- > Bob Walton > Email: http://bwalton.com/cgi-bin/emailbob.pl Bob, Thanks for your input, and setting me straight on Double Quotes .vs. Single Quotes in WINders, etc. Seems like you even beat the Relay Chat folks too !!! IRC - UnderNet - #perl [18:08] < tomatoe > I was reading some of the comp.lang.perl.misc newsgroup and came upon this line of code in a message: [18:08] < tomatoe > perl -we 'print join ",", map($_*10,(1..10))' [18:08] < tomatoe > but when I tried to cut-n-paste it into my WIN: ActiveState I got the following Error Message, & don't know why ??? [18:08] < tomatoe > Can't find string terminator "'" anywhere before EOF at -e line 1. ... [19:37] < black-ice > tomatoe: on windows use " not ' for -e perl lines [19:37] < black-ice > so, that means you will need to fix the "" inside the oneliner as well. [19:38] < black-ice > so perl -we "print join ',',map($_*10,(1..10))" ... D:\study\perl\WIP>perl -we "print join ',',map($_*10,(1..10))" 10,20,30,40,50,60,70,80,90,100 [21:45] < tomatoe > ty black-ice, Quotes " on the outside, & singleQuote on the inside ' worked - take care M.D.
Post Follow-up to this message"Steven Kuo" <skuo@mtwhitney.nsc.com> wrote in message news:Pine.GSO.4.21.0504261710090.27341-100000@mtwhitney.nsc.com... > On Wed, 27 Apr 2005, Dan Jacobson wrote: > > > > If you're inquring about "perl golf", then the best I could do was: > > $ perl -e '$,="0,";print 1..10,"\b"' > > -- > Regards, > Steven > Go get em Tiger :) ... U folks have some killer coding ways: Generic perl golf rules: http://www.xs4all.nl/~thospel/golf/rules.html very interesting. - thanks & take care M.D. <aka> _ _ | |_ ___ _ __ ___ __ _ | |_ ___ ___ | __| / _ \ | '_ ` _ \ / _` | | __| / _ \ / _ \ | |_ | (_) | | | | | | | | (_| | | |_ | (_) | | __/ \__| \___/ |_| |_| |_| \__,_| \__| \___/ \___|
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.