Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

10,20,30,40
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Dan Jacobson
04-27-05 01:57 AM


Re: 10,20,30,40
* 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

Report this thread to moderator Post Follow-up to this message
Old Post
Fabian Pilkowski
04-27-05 08:57 AM


Re: 10,20,30,40
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


Report this thread to moderator Post Follow-up to this message
Old Post
Steven Kuo
04-27-05 08:57 AM


Re: 10,20,30,40
* 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

Report this thread to moderator Post Follow-up to this message
Old Post
Fabian Pilkowski
04-27-05 08:57 AM


Re: 10,20,30,40
"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>
_                                _
| |_   ___    _ __ ___     __ _  | |_   ___     ___
| __| / _ \  | '_ ` _ \   / _` | | __| / _ \   / _ \
| |_ | (_) | | | | | | | | (_| | | |_ | (_) | |  __/
\__| \___/  |_| |_| |_|  \__,_|  \__| \___/   \___|





Report this thread to moderator Post Follow-up to this message
Old Post
Michael De Tomaso
04-27-05 08:57 AM


Re: 10,20,30,40
Michael 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

Report this thread to moderator Post Follow-up to this message
Old Post
Bob Walton
04-27-05 08:57 AM


Re: 10,20,30,40
"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.



Report this thread to moderator Post Follow-up to this message
Old Post
Michael De Tomaso
04-27-05 08:57 AM


Re: 10,20,30,40
"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>
_                                _
| |_   ___    _ __ ___     __ _  | |_   ___     ___
| __| / _ \  | '_ ` _ \   / _` | | __| / _ \   / _ \
| |_ | (_) | | | | | | | | (_| | | |_ | (_) | |  __/
\__| \___/  |_| |_| |_|  \__,_|  \__| \___/   \___|





Report this thread to moderator Post Follow-up to this message
Old Post
Michael De Tomaso
04-27-05 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Miscellaneous archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:32 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.