[25779] in Perl-Users-Digest
Perl-Users Digest, Issue: 8018 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 26 21:05:45 2005
Date: Tue, 26 Apr 2005 18:05:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 26 Apr 2005 Volume: 10 Number: 8018
Today's topics:
'\n' & <br> problem <hackeras@gmail.com>
Re: '\n' & <br> problem <hackeras@gmail.com>
Re: '\n' & <br> problem <noreply@gunnar.cc>
10,20,30,40 <jidanni@jidanni.org>
Re: 10,20,30,40 <pilkowsk@informatik.uni-marburg.de>
Re: 10,20,30,40 <skuo@mtwhitney.nsc.com>
Re: A new scripting language Tao 0.9.0 beta released! <NOSPAM.Lhota.adarose@verizon.net>
Re: ANN: A new scripting language Tao 0.9.0 beta releas <knode.wants.this@see.sigblock>
Re: one-time and one-line programs <mdetomaso@bak.rr.com>
Re: one-time and one-line programs <abigail@abigail.nl>
Re: one-time and one-line programs <abigail@abigail.nl>
Re: Speeding up glob? <No_4@dsl.pipex.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Apr 2005 00:35:37 +0300
From: Nikos <hackeras@gmail.com>
Subject: '\n' & <br> problem
Message-Id: <d4mc77$er1$1@nic.grnet.gr>
if( param('select') ) {
$data = open_script( $host, param('select') );
} elsif( $match ) {
$data = welcome_old( $host );
} else {
$data = welcome_new( $host );
}
sub welcome_old {
my ($host) = @_;
$dbh->do( "UPDATE guestlog SET hostcount = hostcount + 1 WHERE
host='$host'" );
my $sth = $dbh->prepare( "SELECT * FROM guestlog WHERE
host='$host'" );
$sth->execute();
my $row = $sth->fetchrow_hashref;
return "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåéò ôçí
óåëßäá åíäéáöÝñïõóá!\n".
"Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
.$row->{date}. " !!\n".
"ÓýíïëéêÝò Þñèåò åäþ " .$row->{hostcount}. " öïñÝò !!!\n".
"Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{script}. " }\n".
"Ðïéü êåßìåíï èá ìåëåôÞóåéò áõôÞí ôçí öïñÜ !?";
}
When i have '\n' then my script print blank lines, if i change it to
<br> it does not, why?
Also i have to use these if i want my script to print ok the fiel it
opens. maybe i dotn have to when <br> works!
$data =~ s/\n/\\n/g;
$data =~ s/"/\\"/g;
$data =~ tr/\cM//d;
------------------------------
Date: Wed, 27 Apr 2005 00:57:08 +0300
From: Nikos <hackeras@gmail.com>
Subject: Re: '\n' & <br> problem
Message-Id: <d4mdfi$fto$1@nic.grnet.gr>
Nikos wrote:
The $data then would pass to the index.html which is a template file and
then $data would be printed by javascript like this:
var textToShow = "<TMPL_VAR name=data>";
So if it contains chars like ' or " or \ or / that would be a problem right?
At least in my old index.pl (the one with cgi.pm) there was problem
printing it.
What can i do?
------------------------------
Date: Wed, 27 Apr 2005 00:03:11 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: '\n' & <br> problem
Message-Id: <3d7s4vF6rfvmhU1@individual.net>
Nikos wrote:
<snip>
> return "Êáëþò Þëèåò " .$host. "! ×áßñïìáé ðïõ âñßóêåéò ôçí
> óåëßäá åíäéáöÝñïõóá!\n".
> "Ôåëåõôáßá öïñÜ Þñèåò åäþ ùò " .$row->{host}. " óôéò "
> .$row->{date}. " !!\n".
> "ÓýíïëéêÝò Þñèåò åäþ " .$row->{hostcount}. " öïñÝò !!!\n".
> "Ôåëåõôáßá åßäåò ôï êåßìåíï { " .$row->{script}. " }\n".
> "Ðïéü êåßìåíï èá ìåëåôÞóåéò áõôÞí ôçí öïñÜ !?";
> }
>
> When i have '\n' then my script print blank lines, if i change it to
> <br> it does not, why?
The code you posted doesn't print anything AFAICS.
Nikos, you seem to try using this group as a substitute for own
studying. As you should have understood by now, that's not appreciated.
Please take a step back and start reading about the basics of HTML and
CGI. As regards CGI scripts in Perl, you can find a few online tutorials
at http://cgi.resourceindex.com/Documentation/CGI_Tutorials/
When you come back here, please respect the posting guidelines and try
to express yourself clearly. For instance, if a program does not behave
as you had expected, write a *small* but *complete* program that
illustrates just that behaviour (i.e. don't post a lot of code that
irrelevant to the problem in question).
If you do so, you'll be welcome to ask questions here.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 27 Apr 2005 04:31:32 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: 10,20,30,40
Message-Id: <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.
------------------------------
Date: Wed, 27 Apr 2005 02:04:41 +0200
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: 10,20,30,40
Message-Id: <3d836bF6qtja0U1@individual.net>
* 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
------------------------------
Date: Tue, 26 Apr 2005 17:12:55 -0700
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: 10,20,30,40
Message-Id: <Pine.GSO.4.21.0504261710090.27341-100000@mtwhitney.nsc.com>
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
------------------------------
Date: Tue, 26 Apr 2005 19:31:01 GMT
From: "Frank J. Lhota" <NOSPAM.Lhota.adarose@verizon.net>
Subject: Re: A new scripting language Tao 0.9.0 beta released!
Message-Id: <VFwbe.3315$u56.3050@trndny09>
"Fu Limin" <fu.limin.tao@gmail.com> wrote in message
news:b35444fb.0504260741.226944fb@posting.google.com...
> ===============
> Key Features:
> ===============
> 1. Object-oriented ( syntax slightly similar to C++ ).
> 2. String regular expression with syntax support ( similar to Perl ).
> 3. Numeric types and their operations ( slightly similar to Matlab ).
> 4. Extendable with C++ through a simple and transparent interface.
What! No backtracking and goal-driven evaluation?!
------------------------------
Date: Tue, 26 Apr 2005 18:59:09 -0400
From: Kenneth Downs <knode.wants.this@see.sigblock>
Subject: Re: ANN: A new scripting language Tao 0.9.0 beta released!
Message-Id: <dpt2k2-8fa.ln1@pluto.downsfam.net>
Fu Limin wrote:
> Dear all,
>
> I am glad to announce in this forum that the lastest version of a new
> scripting language Tao has come
> out. Welcome to try it out!
>
<snip>
In all sincerity, sounds like you described PHP. What does Tao have that
would draw anyone away from PHP?
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
------------------------------
Date: Tue, 26 Apr 2005 18:26:56 GMT
From: "Michael De Tomaso" <mdetomaso@bak.rr.com>
Subject: Re: one-time and one-line programs
Message-Id: <QJvbe.21217$JB.7438@tornado.socal.rr.com>
"Wes Groleau" <groleau+news@freeshell.org> wrote in message
news:d4kfb8$p5g$2@domitilla.aioe.org...
> Michael De Tomaso wrote:
>> Q:I'd like to know how many perl people keep a stash of one liners and
>> what are their favorite quickie code concoctions might be ?
>
> If it's worth keeping, it's worth keeping in a script and
> adding a little bit of flexibility to it.
>
> The only one-liners I can remember using in a long time are
> search-and-replace, i.e.,
>
> perl -p -i -e 's^old^new^g;' *
>
> --
> Wes Groleau
>
> Answer not a fool according to his folly,
> lest thou also be like unto him.
> Answer a fool according to his folly,
> lest he be wise according to his own conceit.
> -- Solomon
>
> Are you saying there's no good way to answer a fool?
> -- Groleau
Thank you all. And in an abstract sense I do keep one-liners, but in an ole
ASCII file that I keep year by year, and DOS-grep it to death as time
marches on, then cut-n-paste the bits of wisdom that have been collected, or
at least I thought it was hot at the time, and occasionally I'll keep an
additional logs for certain subjects, etc, for example:
D:\BAT>grep.exe books d:\data\textfile.(s)\daily\PLOG2005.LOG
file ...
R:\Drive-I.L\internet\uuasc.org\perl_books_UUASC_library-requests.txt
- take care M.D.
The Fool On The Hill
John Lennon and Paul McCartney
Verse 1
Day after day alone on a hill the
man with the fool grin is keeping perfectly still, But
nobody wants to know him, they can see that he's justa fool and
he never gives an answer.
Chorus
But the fool on the hill sees the sun going down and the
eyes in his head see the world spinning round
...---... get in the SUB Jeremy :)
------------------------------
Date: 26 Apr 2005 23:21:49 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: one-time and one-line programs
Message-Id: <slrnd6tj8d.t5e.abigail@alexandra.abigail.nl>
Tad McClellan (tadmc@augustmail.com) wrote on MMMMCCLV September MCMXCIII
in <URL:news:slrnd6qo4q.ruu.tadmc@magna.augustmail.com>:
)) Michael De Tomaso <mdetomaso@bak.rr.com> wrote:
)) > In reviewing the -p -e -n command line options, I've been trying to
)) > find/understand more examples...
)) >
)) > Q:I'd like to know how many perl people keep a stash of one liners and what
)) > are their favorite quickie code concoctions might be ?
))
))
)) perl -n -e 'print' file1 file2... # cat
))
)) perl -pe1 file1 file2.... # Tiger Woods cat
))
)) perl -n -e 'print if /PATTERN/' file1 file2... # grep -h
))
)) perl -n -e 'print "$ARGV: $_" if /PATTERN/' file1... # grep -H
))
)) perl -p -i -e 'tr/\r//d' file1 file2... # dos2unix
))
)) perl -p -i -e 's/\n/\r\n/' file1 file2... # unix2dos
))
)) perl -p -e 'tr/a-zA-Z/n-za-mN-ZA-M/' file1... # rot13
perl -pe '}{*_=*.}{' file # wc -l
perl -F: -lane 'print $F [2]' /etc/passwd # print UIDs.
perl -ple '$_=y___c' file1 file2 ... # Print line lengths
Abigail
--
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'
------------------------------
Date: 26 Apr 2005 23:28:52 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: one-time and one-line programs
Message-Id: <slrnd6tjlk.t5e.abigail@alexandra.abigail.nl>
Bart Lateur (bart.lateur@pandora.be) wrote on MMMMCCLVI September
MCMXCIII in <URL:news:4k3s61pi3urfld04fdjpn1lvl4252mi8tq@4ax.com>:
'' John Bokma wrote:
''
'' >Since I rarely use -p, -n, -s, -F, it might be not the best stuff to read.
'' >
'' >I use -e often to check something, or do something that's easier with perl
'' >compared to the cli.
''
'' I disagree for -p and -n, they're not in the same league as -e, but stil
'' lvery useful.
''
'' And another one to use is -l (little L), because then a print will add a
'' newline. Easier than typing "\n".
For one-liners, I use on a regular bases:
-a, -c, -Dr, -e, -F, -i, -I, -l, -M, -n, -p, -v, -V, and -w.
Although -v and -V aren't really used for 'one-liners'.
Abigail
--
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
print } sub __PACKAGE__ { &
print ( __PACKAGE__)} &
__PACKAGE__
( )
------------------------------
Date: Wed, 27 Apr 2005 00:27:22 +0100
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Speeding up glob?
Message-Id: <t7ydnSDAxu7BU_PfRVnyig@pipex.net>
> Jim wrote:
>.....
>> There are several thousand files (~21K) in this directory
Which is a cause of your problem. And it will cause you problems every
time you try to access any of the files too.
If you had 21000 documents you wouldn't throw them all into one drawer
and expect to find one quickly. You'd arrange them by some category and
put each category into a separate drawer. File system have directory
hierarchy for just such an arrangement. If you use the facility you will
find your code runs much faster.
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8018
***************************************