Home > Archive > PERL Miscellaneous > April 2005 > 10,20,30,40
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Dan Jacobson 2005-04-26, 8:57 pm |
| 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.
| |
| Fabian Pilkowski 2005-04-27, 3:57 am |
| * 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
| |
| Steven Kuo 2005-04-27, 3:57 am |
| On 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
| |
| Fabian Pilkowski 2005-04-27, 3:57 am |
| * 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
| |
| Michael De Tomaso 2005-04-27, 3:57 am |
|
"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>
_ _
| |_ ___ _ __ ___ __ _ | |_ ___ ___
| __| / _ \ | '_ ` _ \ / _` | | __| / _ \ / _ \
| |_ | (_) | | | | | | | | (_| | | |_ | (_) | | __/
\__| \___/ |_| |_| |_| \__,_| \__| \___/ \___|
| |
| Bob Walton 2005-04-27, 3:57 am |
| Michael De Tomaso wrote:
> "Dan Jacobson" <jidanni@jidanni.org> wrote in message
> news:877jip700r.fsf@jidanni.org...
....
....[color=darkred]
> 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
| |
| Michael De Tomaso 2005-04-27, 3:57 am |
| "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.
| |
| Michael De Tomaso 2005-04-27, 3:57 am |
|
"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>
_ _
| |_ ___ _ __ ___ __ _ | |_ ___ ___
| __| / _ \ | '_ ` _ \ / _` | | __| / _ \ / _ \
| |_ | (_) | | | | | | | | (_| | | |_ | (_) | | __/
\__| \___/ |_| |_| |_| \__,_| \__| \___/ \___|
|
|
|
|
|