[22162] in Perl-Users-Digest
Perl-Users Digest, Issue: 4383 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 11 09:05:37 2003
Date: Sat, 11 Jan 2003 06:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 11 Jan 2003 Volume: 10 Number: 4383
Today's topics:
$size = -s /home/temp/$_" Doesn't work (juha)
Re: Converting CGI to XML <usenet@tinita.de>
Re: Converting CGI to XML (Keith R.)
FULL VERSION: Hi all gurus. What is wrong in my scrip (juha)
Re: FULL VERSION: Hi all gurus. What is wrong in my s <tassilo.parseval@post.rwth-aachen.de>
Re: How does one determine why perl prog runs so slow?? (Sisyphus)
Re: How does one Iterate an array to remove duplicates? (Lance)
Re: Internet chat CGI script <anthonysaffer@NOSPAM.yahoo.com>
Re: Matching entries in lists <goldbb2@earthlink.net>
parsing a textarea field (Dhruv)
Re: parsing a textarea field <mpapec@yahoo.com>
Picking out options in argv <starfury@cats.ucsc.edu>
Re: Picking out options in argv <ian@WINDOZEdigiserv.net>
Re: Picking out options in argv <nobody@dev.null>
Re: stucked <goldbb2@earthlink.net>
Re: suggested revisions for the Posting Guidelines <parv_fm@emailgroupsWhereElse.com>
Using tr/// - Am I barking up the wrong tree? (R. Charles Henry)
Re: Using tr/// - Am I barking up the wrong tree? (Jay Tilton)
Re: Using tr/// - Am I barking up the wrong tree? <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Jan 2003 05:04:14 -0800
From: salmjuh@hotmail.com (juha)
Subject: $size = -s /home/temp/$_" Doesn't work
Message-Id: <c9858ca5.0301110504.3334673f@posting.google.com>
Hi all gurus. What is wrong in my script?
I need to check if the file is complity on my disk from FTP program.
So I check the file's size and wait a while and check it again. If
size is same file is ready for action else do nothing. Here is what I
can't get work:
while (<TEXTFILE>) {
$size1 = -s "/temp/$_";
system('sleep 20');
$size2 = -s "/temp/$_";
if ($size1 = $size2 ) {
------------------------------
Date: 11 Jan 2003 12:28:37 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: Converting CGI to XML
Message-Id: <tinh8jw2a$3op$tina@news01.tinita.de>
Kåre Olai Lindbach <barbr-en@online.no> wrote:
> On 10 Jan 2003 11:17:27 GMT, Tina Mueller <usenet@tinita.de> wrote:
>>Keith R. <kmrob72@comcast.net> wrote:
>>> Does anybody know if it's possible to convert CGI to XML?
>>
>>s/CGI/XML/;
>>
>>SCNR =)
> $Tina =~ s/SMOKER/NON_SMOKER/;
not yet... =)
but i'll work on it until Paris...
tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/ \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: 11 Jan 2003 05:58:54 -0800
From: kmrob72@comcast.net (Keith R.)
Subject: Re: Converting CGI to XML
Message-Id: <745194ed.0301110558.4dcf210d@posting.google.com>
"Harald H.-J. Bongartz" <bongie@gmx.net> wrote in message news:<1403504.j9bPFYRLJS@nyoga.dubu.de>...
> Malcolm Dew-Jones wrote:
> > Or more commonly
> >
> > while ($Tina =~ /SMOKER/)
> > {
> > $Tina =~ s/SMOKER/NON_SMOKER/;
> > }
>
> You should give her a cigarette break somewhere in that endless loop.
> ;-)
>
> Ciao,
> Harald
Thanks for the help. I was reading about a script, I believe a perl
script, that would parse the objects in a CGI script into XML. It was
an extremely vague explaination. I thought it would be interesting to
try and convert the CGI scripts in Bugzilla and Bonsai to use XML. I
suppose Java is an option also. We'll see :-)
Keith
------------------------------
Date: 11 Jan 2003 05:08:27 -0800
From: salmjuh@hotmail.com (juha)
Subject: FULL VERSION: Hi all gurus. What is wrong in my script?
Message-Id: <c9858ca5.0301110508.5b4d6460@posting.google.com>
I need to check if the file is complity on my disk from FTP program.
So I check the file's size and wait a while and check it again. If
size is same as firts time, file is ready for action, else do nothing.
Here is what I can't get work:
while (<TEXTFILE>) {
$size1 = -s "/temp/$_";
system('sleep 20');
$size2 = -s "/temp/$_";
if ($size1 = $size2 ) {
do something;
}
}
Why this woun't work ?
Thanks for any help.
-js
------------------------------
Date: 11 Jan 2003 13:16:40 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: FULL VERSION: Hi all gurus. What is wrong in my script?
Message-Id: <avp5fo$jcm$1@nets3.rz.RWTH-Aachen.DE>
Also sprach juha:
> I need to check if the file is complity on my disk from FTP program.
> So I check the file's size and wait a while and check it again. If
> size is same as firts time, file is ready for action, else do nothing.
> Here is what I can't get work:
There are two problems: newlines and the wrong operator:
> while (<TEXTFILE>) {
$_ now contains a string terminated with a newline. Add this:
chomp; # get rid of newlines at the end of $_
> $size1 = -s "/temp/$_";
> system('sleep 20');
> $size2 = -s "/temp/$_";
>
> if ($size1 = $size2 ) {
This is an assignment not a comparison. It is always true when $size2
has a true value. Change to:
if ($size1 == $size2) {
> do something;
> }
>
> }
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 11 Jan 2003 03:20:52 -0800
From: kalinabears@hdc.com.au (Sisyphus)
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <e615828f.0301110320.53b7b922@posting.google.com>
R.Mariotti@FinancialDataCorp.com (Bob Mariotti) wrote in message news:<3e1f9aaf.7348417@news.cshore.com>...
> Honestly! I HAVE searched this group, other perl sites, perlfaqs, etc
> and I cannot find anything that actually covers this topic. It IS
> perl so I'm posting in the perl group.
>
> I have a perl program that has been in production for a couple of
> years. It was originally developed under perl 5.005 running under the
> IBM AIX version 4.2.1 OS. Performance was blazingly fast.
>
> Some months ago we upgraded our servers OS to IBM AIX version 5.1
> which comes with perl 5.6 but I could NOT get DBI/DBD installed to
> link to MySQL.
>
> Finally I downloaded the source for Perl 5.8 and compiled it cleanly
> using gcc which I obtained from the Bull Freeware site.
>
> Upon completion the perl program(s) along with MySQL functioned fine.
> Great news! I though.
>
> Here's the scope of the application:
>
> We builld a database (MySQL type MyIsam) about 30 MB in size.
>
> We then have a large sequential file (3 million records) which our
> program reads. It does a pattern match on each line and upon the
> detection of certain lines it randomly accesses the MySQL database to
> obtain some info.
>
> It them conditionally outputs a small sequential file.
>
> On the prior OS this process would run to completion in less than one
> hour.
>
> Now - on the new OS version with Perl 5.8 the same program using the
> same data files and database took over FORTY EIGHT HOURS to complete.
>
> I ruled our a MySQL issue because if I comment out the MySQL access
> the run time is still incredibly slow.
>
> So, here's my question for the perl guru's that I could not find in
> the faqs or other resources:
>
> How does one go about determining what may be the cause of this
> unacceptable performance? I researched the module Benchmark but that
> only measures time. Where should one start? Is this an issue that
> others have experienced (I'm sure) and what was done to overcome it?
>
> BTW - the performance on our non-perl applications still rockets along
> so I don't think its the system/OS itself.
>
> I will be eagerly awaiting any and all suggestions.
>
> Bob
You haven't inadvertently compiled a debug version of perl, have you ?
(The makefile that I used to build perl had the debug options as
default - which I had to remove.)
Mind you, I don't know whether that would account for a slowdown of
that magnitude.
Just a thought.
Cheers,
Rob
------------------------------
Date: 10 Jan 2003 21:51:58 -0800
From: ls@worldpath.net (Lance)
Subject: Re: How does one Iterate an array to remove duplicates?
Message-Id: <c48c82ed.0301102151.47dce0@posting.google.com>
Harald,
What can I say? This was more then I ever expected. You not only
helped with my problem, but I learned a ton from it too!
I had heard, and read in Camel and Llama that the Perl communitee was
unlike any other. This experience certainly backs that up.
Thank you very much!!
-Lance
"Harald H.-J. Bongartz" <bongie@gmx.net> wrote in message news:<5666900.hOb4xdXVof@nyoga.dubu.de>...
> Lance wrote:
> > I need to audit a web server to find out which web dirs have cgi
> > installed, and the same for FPX and which are using php. I have come
> > up with a way to search out these directories and compile a list.
> > However, I need a way to iterate through the list to remove duplicate
> > parent directories. Here is what I have thus far;
>
> First some comments on your code:
>
> > #! /usr/bin/perl -w
>
> You enable warnings - good!
> Even better would be to use strictures and declare your variables so you
> find typos more easily:
> use strict;
>
> > @cgi = `find /www3 -name cgi-bin`;
>
> Should be changed to
> my @cgi = ...
> with strictures enabled.
>
> Maybe you want to restrict the search to directories:
> find /www3 -name cgi-bin -type d
> but that's just a remark.
>
> > @fpx = `find /www3 -name "*_vti_pvt*"`;
>
> see above
>
> > foreach $domain (@cgi) {
>
> foreach my $domain (@cgi) {
>
> Reduce the scope of your variables. This way, $domain is local to the
> loop, as it should be.
>
> > if ($domain =~ m#^/#) {
> > $domain =~ s#/cgi-bin##;
> > push(@newcgi, "${domain}");
>
> Neither quotes nor braces are needed here.
> push @newcgi, $domain;
>
> > }
> > }
> >
> > foreach $domain (@fpx) {
> > if ($domain =~ m#^/#) {
> > $domain =~ s#/_vti_pvt##;
> > push(@newfpx, "${domain}");
> > }
> > }
>
> like above
>
> >
> > open(WEBS, ">>/www2/kryhavok/websaudit");
>
> ALWAYS check the result of an open():
> open (WEBS, ">>/www2/kryhavok/websaudit")
> or die "cannot open websaudit: $!";
>
> > print WEBS "\#\#These have CGI installed\#\#\n\n";
>
> No need to escape a hash sign.
>
> > print WEBS sort @newcgi;
> > print WEBS "\n\#\#These have FPX installed\#\#\n\n";
>
> see above
>
> > print WEBS sort @newfpx;
> > close(WEBS);
>
> Well, at first I was tempted just to insert improvements into your code,
> but then I decided that it might be more helpful to rewrite it.
>
> -------------------- snip --------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> # gather all global variables at the top
> # file-scoped variables with uppercase first letter,
> # to distinguish from other locals
> my $Root = '/www3';
> my $Websaudit = '/www2/kryhavok/websaudit';
>
> # parametrize the patterns with the to "areas" CGI and FPX
> my %FilePatterns = (
> CGI => 'cgi-bin',
> FPX => '*_vti_pvt*',
> );
> my %ReplacePatterns = (
> CGI => '/cgi-bin',
> FPX => '/_vti_pvt',
> );
>
> # open the log in append mode
> open(WEBS, ">>$Websaudit")
> or die "cannot open $Websaudit: $!";
>
> # loop over both areas (thus avoiding duplicated code)
> for my $area (qw(CGI FPX)) {
> my %newmatches = ();
>
> # get find result -> match results and do replacement -> sort
> my @matches = sort
> grep {m#^/# && s#$ReplacePatterns{$area}$## }
> `find $Root -name "$FilePatterns{$area}"`;
>
> # I don't like dangling linebreaks
> chomp (@matches);
>
> DOMAINLOOP: foreach my $domain (@matches) {
> my $position = length($domain);
>
> # search through all parent directories
> # if we had indexed that already (@matches are sorted, so
> # the parent dir will always be checked *before* any child!)
> while (($position = rindex ($domain, '/', $position-1)) > 0) {
> next DOMAINLOOP
> if exists $newmatches{substr($domain,0,$position)};
> }
> ++$newmatches{$domain};
> }
>
> # print results; added a time stamp for convenience
> print WEBS "## These have $area installed as of ",
> scalar(localtime), " ##\n\n";
> print WEBS join ("\n", sort keys %newmatches), "\n\n";
> }
>
> close (WEBS);
> exit;
> -------------------- snip --------------------
>
> HTH,
> Harald
------------------------------
Date: Fri, 10 Jan 2003 23:03:31 -0600
From: Anthony M. Saffer <anthonysaffer@NOSPAM.yahoo.com>
Subject: Re: Internet chat CGI script
Message-Id: <p99v1vg2qag8cfp4ufacsocpa8r8v0b30j@4ax.com>
On Thu, 09 Jan 2003 06:34:58 GMT, "Alan Hamlett" <calc83p@yahoo.com>
wrote:
>I do use irc but my school has too much money so they spend it on network
>securtiy for our lan. We go to different schools and cant communicate much
>cus im grounded from the computer(i can only get on after midnight when my
>parents are asleep) and hes grounded from the phone. Our school blocks every
>chat site, blocks downloading any exe or almost anything thats not
>.htm/.html/.txt etc. stuff u can view in a browser. We can get around that
>with perl's get("url"); but they are monotoring my account because my friend
>got expelled(thats why he is at a diff school) for hacking and i helped him
>but didnt get caught cus they didnt have evidence. Thats why i dont even use
>my account at school, i use other peoples accounts and i am in the process
>of getting admin and hopefully root so i can make my own accounts. well ive
>said too much cus the point is i made a cgi chat at
>http://83p.tigalaxy.com/anthem/nt and i am trying to make it better with
>suggestions from other programmers.
I strongly doubt that the problem is "perl limitations" as you
suggested by perhaps the limitations of the medium you're using to
implement your chat (the web). What do you need your chat to do that
you can't make it do? Perhaps that would be a better place to start
than just asking for suggestions. Give us more details and maybe
someone can help you out.
Anthony Saffer
SCS Consulting Services
www.safferconsulting.com
Anthony M. Saffer [Founder & CEO]
SCS Consulting Services
Professional software, database, and web development
http://www.safferconsulting.com
Ph. (918) 542-8251
email: anthonysaffer@NOSPAM.yahoo.com
------------------------------
Date: Sat, 11 Jan 2003 02:39:07 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Matching entries in lists
Message-Id: <3E1FCA1B.B49CE355@earthlink.net>
Anno Siegel wrote:
[snip]
> ( $number, @{ $table->{ $number}} ) if length $number;
> return;
This always returns the empty list. The ($number, @...) on the line
above have no effect.
Personally, I would have written this code as:
sub lookup {
my ($table, $number) = @_;
while( length $number ) {
if( my $entry = $table->{$name} ) {
return ($number, @$entry);
}
chop $number;
}
return ();
}
Which clearly seperates the two different exit points.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 11 Jan 2003 01:02:21 -0800
From: dmalhotr2001@yahoo.com (Dhruv)
Subject: parsing a textarea field
Message-Id: <b6d0b0b.0301110102.3d243f23@posting.google.com>
Hi,
My question is that If I have a textarea field
i.e.
-----
hello
how
are
you
----
and I would like to take each word and dump into a database,
extracting each bit by a newline character.
For example
hello, how, are, you would be different fields in the database.
1. How would I go about doing this?
2. Is there a tutorial(s) that would explain this or something
similar?
Thanks
Dhruv
------------------------------
Date: Sat, 11 Jan 2003 12:33:10 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: parsing a textarea field
Message-Id: <j2002vohjcsdi0uvogq7vqch4soqdkpvv6@4ax.com>
X-Ftn-To: Dhruv
dmalhotr2001@yahoo.com (Dhruv) wrote:
>2. Is there a tutorial(s) that would explain this or something
>similar?
Yes, you can start with:
http://www.perldoc.com/perl5.8.0/pod/perlrequick.html
http://www.perldoc.com/perl5.8.0/pod/perlretut.html
--
Matija
------------------------------
Date: Fri, 10 Jan 2003 23:07:06 -0800
From: "John Tuong" <starfury@cats.ucsc.edu>
Subject: Picking out options in argv
Message-Id: <3e1fc299$1@news.ucsc.edu>
This is my first time using perl, and the perl code i made to grab options
so far is very cumbersome and c related which makes me think I'm headed
towards the wrong direction. Especially my constant use of if/else which is
already bad coding style... any clue as to what kind of perl function will
hold true to perl's power and do all these in fewer steps?
(code doesn't necessarily work.. i stopped after i realized i went in the
wrong direction)
while ($x = shift @ARGV) {
if($x =~ /-T/) {
$x = shift @ARGV;
print "quote: postscripting endquote\n" if($x =~ /ps/);
print "groffing\n" if($x =~ /groff/);
print "pdf'ing\n" if($x =~ /pdf/);
} elsf($x =~ /-fT/) {
print "Time Roman Font\n";
} elsf($x =~ /-fN/) {
print "NewCenturySchlbk\n";
} elsf($x =~ /-fH/) {
print "Helvetica\n";
} elsf($x =~ /-ps/) {
$x = shift @ARGV;
if ($x =~ /-.*/) {
die "Invalid points type\n";
}
$pspoint = $x;
} elsf($x =~ /-vs/) {
$x = shift @ARGV;
if ($x =~ /-.*/) {
die "Invalid points type\n";
}
$vspoint = $x;
}
}
------------------------------
Date: Sat, 11 Jan 2003 08:07:54 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Picking out options in argv
Message-Id: <k2kv1vot2lameorqhle6m4m6nsp9of27v8@4ax.com>
Keywords: Remove WINDOZE to reply
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In a fit of excitement on Fri, 10 Jan 2003 23:07:06 -0800, "John Tuong"
<starfury@cats.ucsc.edu> managed to scribble:
> This is my first time using perl, and the perl code i made to grab
> options so far is very cumbersome and c related which makes me think
> I'm headed towards the wrong direction. Especially my constant use
> of if/else which is already bad coding style... any clue as to what
> kind of perl function will hold true to perl's power and do all these
> in fewer steps?
>
> (code doesn't necessarily work.. i stopped after i realized i went in
> the wrong direction)
>
> while ($x = shift @ARGV) {
> if($x =~ /-T/) {
> $x = shift @ARGV;
> print "quote: postscripting endquote\n" if($x =~ /ps/);
> print "groffing\n" if($x =~ /groff/);
> print "pdf'ing\n" if($x =~ /pdf/);
> } elsf($x =~ /-fT/) {
> print "Time Roman Font\n";
> } elsf($x =~ /-fN/) {
> print "NewCenturySchlbk\n";
> } elsf($x =~ /-fH/) {
> print "Helvetica\n";
> } elsf($x =~ /-ps/) {
> $x = shift @ARGV;
> if ($x =~ /-.*/) {
> die "Invalid points type\n";
> }
> $pspoint = $x;
> } elsf($x =~ /-vs/) {
> $x = shift @ARGV;
> if ($x =~ /-.*/) {
> die "Invalid points type\n";
> }
> $vspoint = $x;
> }
> }
>
Perl has a module for this. For example:
use Getopt::Long;
This will allow for '--option' switches.
HTH.
Regards,
Ian
-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3
iQA/AwUBPh/Q2Gfqtj251CDhEQLLLwCgsvscRmYo9PI/+jm2PWcC42ESxYIAoOyg
OIMVf9B7NKvVakG6CEi4BYbp
=kULC
-----END PGP SIGNATURE-----
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Scripting, Web design, development & hosting.
------------------------------
Date: Sat, 11 Jan 2003 13:48:52 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Picking out options in argv
Message-Id: <3E201FE6.9040007@dev.null>
John Tuong wrote:
>[...]
>
> (code doesn't necessarily work.. i stopped after i realized i went in the
> wrong direction)
>
> while ($x = shift @ARGV) {
> if($x =~ /-T/) {
> $x = shift @ARGV;
> print "quote: postscripting endquote\n" if($x =~ /ps/);
> print "groffing\n" if($x =~ /groff/);
> print "pdf'ing\n" if($x =~ /pdf/);
> } elsf($x =~ /-fT/) {
>
Ian.H has already given you a substantive answer to your question. I
only want to point out to you that you consistently use "elsf" where the
correct idiom is "elsif".
------------------------------
Date: Sat, 11 Jan 2003 02:31:15 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: stucked
Message-Id: <3E1FC843.53A4FB6F@earthlink.net>
Mats wrote:
>
> Hi
>
> I'm building a threaded messageboard with perl and mysql but I can't
> come up with an algoritm for threading the messages, I have looked
> over the net to find something that could lead me in the right
> direction but can't find anything.
The one true message threading algorithm :) can be found at:
http://www.jwz.org/doc/threading.html
It's designed to be quite robust, and work reasonably well (if not quite
perfectly) in those cases where some messages don't list all the
articles they refer to.
Since you're using it for a message board, you can garuntee that each
message lists *all* the messages that it refers to, which will ensure
that threading is done properly.
> Isn't this a common task in cgi-programming?
Not really.
The most common use of message threading is for news readers. And while
that does include news-to-web gateways, such as groups.google.com, this
isn't a common cgi task.
Most message boards simply list messages in chronological order, and
don't bother with threading.
> ...the positive thing is that I have learned a _lot_ about hashes...
Hashes are good! If you don't understand hashes, you don't understand
perl.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Sat, 11 Jan 2003 05:31:45 GMT
From: parv <parv_fm@emailgroupsWhereElse.com>
Subject: Re: suggested revisions for the Posting Guidelines
Message-Id: <slrnb1vb7g.2c4g.parv_fm@localhost.holy.cow>
in message <u9znq8lxhi.fsf@wcl-l.bham.ac.uk>,
wrote Brian McCauley ...
> Do you (by which I mean the nettizens as of clp* as a whole, not
> just Tad) want me to go though the whole document to find other
> stuff like this
please do. i personally appreciate your efforts and concise & clear
text in general.
> or do people prefer the more wordy style?
for that we have so many software use agreements, credit card co.'s
policies, and privacy statements to read.
- parv
--
please don't send me private e-mail.
if you must, do away w/ WhereElse in the address.
------------------------------
Date: 10 Jan 2003 21:17:45 -0800
From: trapforcannedmeatproduct@hotmail.com (R. Charles Henry)
Subject: Using tr/// - Am I barking up the wrong tree?
Message-Id: <8ed56b42.0301102117.59612feb@posting.google.com>
Trying to convert individual letters in a string, to gif image HTML tags:
e.g.
from
jo@jo.com
to
<img src="j.gif"><img src="o.gif"><img src="at.gif"><img src="j.gif"> etc.
by using
$string =~ tr/a-z/<img src='..\/a.gif'>-<img src='..\/z.gif'>/;
is there an easier way of doing this?
------------------------------
Date: Sat, 11 Jan 2003 06:25:56 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Using tr/// - Am I barking up the wrong tree?
Message-Id: <3e1fb595.97911321@news.erols.com>
On 10 Jan 2003 21:17:45 -0800, trapforcannedmeatproduct@hotmail.com
(R. Charles Henry) wrote:
: Trying to convert individual letters in a string, to gif image HTML tags:
:
: e.g.
:
: from
:
: jo@jo.com
:
: to
:
: <img src="j.gif"><img src="o.gif"><img src="at.gif"><img src="j.gif"> etc.
:
: by using
:
: $string =~ tr/a-z/<img src='..\/a.gif'>-<img src='..\/z.gif'>/;
:
: is there an easier way of doing this?
Easier than a way that doesn't work? Always.
tr/// is exactly the wrong tool. It changes all instances of one
character into another character. You're looking for s///.
#!perl
use strict;
use warnings;
my $string = 'jo@jo.com';
my %special = (
'@' => 'at',
'.' => 'dot',
# etc.
);
$string =~
s/(.)/sprintf '<img src="%s.gif">', $special{$1} || $1 /eg;
------------------------------
Date: Sat, 11 Jan 2003 06:32:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Using tr/// - Am I barking up the wrong tree?
Message-Id: <ETOT9.1691$%V.658@nwrddc02.gnilink.net>
R. Charles Henry wrote:
> Trying to convert individual letters in a string, to gif image HTML
> tags:
> from
> jo@jo.com
> to
> <img src="j.gif"><img src="o.gif"><img src="at.gif"><img src="j.gif">
>
> $string =~ tr/a-z/<img src='..\/a.gif'>-<img src='..\/z.gif'>/;
> is there an easier way of doing this?
I suspect tr does not do what you think it is doing. tr transliterates
characters 1:1 (except for d and s modifiers). Meaning with the command
above you will get the following translations:
a to <
b to i
c to m
d to g
e to BLANK
f to s
g to r
...
I doubt this is what you want.
One solution is to define an explicit mapping (stored in a hash):
a => '<img scr="j.gif">',
b => '<img scr="b.gif">',
c => '<img scr="c.gif">',
...
'@' => '<img scr="at.gif">',
...
Then "split" the string into individual characters, apply the mapping "for
each" character, and "join" the results back together again.
The advantage is that you can have individual replacements for each
character.
The quick'n dirty solution is to just use a substitute instead of a
transliterate:
s/([a-z])/<img scr="$1.gif">/g;
However this will not handle the case where you want to replace the at sign
with
<img src="at.gif">
or the dot with
<img src="dot.gif">
jue
------------------------------
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.
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 4383
***************************************