[19716] in Perl-Users-Digest
Perl-Users Digest, Issue: 1911 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 11 09:10:26 2001
Date: Thu, 11 Oct 2001 06:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1002805811-v10-i1911@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 11 Oct 2001 Volume: 10 Number: 1911
Today's topics:
sort - only want unique records (Tim O'Sullivan)
Re: sort - only want unique records <Michael.Schlueter@philips.com>
Re: sort - only want unique records <ilya@martynov.org>
String manipulation problem <Anthony.Heuveline@wanadoo.fr>
Re: String manipulation problem <tintin@snowy.calculus>
Re: String manipulation problem (Rafael Garcia-Suarez)
Re: String manipulation problem <s.warhurst@rl.ac.uk>
Re: String manipulation problem <s.warhurst@rl.ac.uk>
Re: String manipulation problem <JPFauvelle@Colt-Telecom.fr>
Re: Translate command rare behaviour? (Anno Siegel)
Re: Translate command rare behaviour? news@roaima.demon.co.uk
Re: Translate command rare behaviour? <JPFauvelle@Colt-Telecom.fr>
Re: YOU ARE ALL GAY! <tmoero@yahoo.com>
Re: YOU ARE ALL GAY! <aort527@hotmail.com>
Re: YOU ARE ALL GAY! (Robert)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Oct 2001 03:55:22 -0700
From: tim.osullivan@cognotec.com (Tim O'Sullivan)
Subject: sort - only want unique records
Message-Id: <40b537f4.0110110255.6a98d403@posting.google.com>
Hi,
I'm new to Perl. I'm trying to sort a numerical list and retrieve
only unique records. Sorting isn't a problem, I use:
sub numerically { $a <=> $b }
@sortedsessions = sort numerically @sessions;
I cannot find how to retrieve only unique records. Can you help?
Tim.
------------------------------
Date: Thu, 11 Oct 2001 13:08:11 +0200
From: "Michael Schlueter" <Michael.Schlueter@philips.com>
Subject: Re: sort - only want unique records
Message-Id: <3bc57dda$0$232$4d4ebb8e@businessnews.de.uu.net>
Hi Tim,
Do you mean records, which occure only once?
If so, you could use a hash, e.g.:
#!/usr/bin/perl -w
@sessions = ... your code;
# run through all elements
foreach $session (@sessions) {
$h{$session}+=1; # creates a frequency distribution
}
# now focus only on the unique ones
foreach $key (%h) {
push @unique_sessions, $h{$key} if $h{$key}==1;
}
@unique_session now contains all sessions, which occure exactly 1 time.
Hope this helps,
Michael Schlueter
------------------------------
Date: 11 Oct 2001 15:17:10 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: sort - only want unique records
Message-Id: <87y9mimnnt.fsf@abra.ru>
>>>>> On 11 Oct 2001 03:55:22 -0700, tim.osullivan@cognotec.com (Tim O'Sullivan) said:
TO> Hi,
TO> I'm new to Perl. I'm trying to sort a numerical list and retrieve
TO> only unique records. Sorting isn't a problem, I use:
TO> sub numerically { $a <=> $b }
TO> @sortedsessions = sort numerically @sessions;
TO> I cannot find how to retrieve only unique records. Can you help?
Every time you need something unique you should think about hash.
my %hash = map +($_ => 1), @array;
my @unique = keys %hash;
or more compact
my @unique = keys %{ { map +($_ => 1), @array } };
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Thu, 11 Oct 2001 13:50:32 +0200
From: "Anthony Heuveline" <Anthony.Heuveline@wanadoo.fr>
Subject: String manipulation problem
Message-Id: <9q4119$e7d$1@wanadoo.fr>
Hi,
I am a newbie in perl so my question should be easy for you to answer... I
have created a CGI script in perl which allows the user to upload a file
using a HTML page. I managed to get the entire local path
(c:/directory/file) but my goal is to get only the file name in this string
(after the last slash).
Does anybody know how to do this?
Thank you for your help.
Anthony.
------------------------------
Date: Thu, 11 Oct 2001 22:00:34 +1000
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: String manipulation problem
Message-Id: <OSfx7.15$Xc4.368676@news.interact.net.au>
"Anthony Heuveline" <Anthony.Heuveline@wanadoo.fr> wrote in message
news:9q4119$e7d$1@wanadoo.fr...
> Hi,
>
> I am a newbie in perl so my question should be easy for you to answer... I
> have created a CGI script in perl which allows the user to upload a file
> using a HTML page. I managed to get the entire local path
> (c:/directory/file) but my goal is to get only the file name in this
string
> (after the last slash).
>
> Does anybody know how to do this?
perldoc File::Basename
------------------------------
Date: 11 Oct 2001 12:02:56 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: String manipulation problem
Message-Id: <slrn9sb2jb.9r9.rgarciasuarez@rafael.kazibao.net>
Anthony Heuveline wrote in comp.lang.perl.misc:
}
} I am a newbie in perl so my question should be easy for you to answer... I
} have created a CGI script in perl which allows the user to upload a file
} using a HTML page. I managed to get the entire local path
} (c:/directory/file) but my goal is to get only the file name in this string
} (after the last slash).
Simple solution :
my $filename = $path;
$filename =~ s,.*/,,;
More portable solution : use the File::Basename module :
my $filename = basename $path;
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
print map substr($_,7).&$_, grep defined &$_, sort values %::;
sub Just {" another "}; sub Perl {" hacker,\n"};
------------------------------
Date: Thu, 11 Oct 2001 13:15:01 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: String manipulation problem
Message-Id: <9q42g6$1ana@newton.cc.rl.ac.uk>
"Anthony Heuveline" <Anthony.Heuveline@wanadoo.fr> wrote in message
news:9q4119$e7d$1@wanadoo.fr...
> I am a newbie in perl so my question should be easy for you to answer... I
> have created a CGI script in perl which allows the user to upload a file
> using a HTML page. I managed to get the entire local path
> (c:/directory/file) but my goal is to get only the file name in this
string
> (after the last slash).
This will do it:
$file = "c:/directory/file";
$filename =
substr($file,rindex($file,"/")+1,length($file)-rindex($file,"/"));
Spencer
------------------------------
Date: Thu, 11 Oct 2001 13:18:04 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: String manipulation problem
Message-Id: <9q42lt$1ahi@newton.cc.rl.ac.uk>
"S Warhurst" <s.warhurst@rl.ac.uk> wrote in message
news:9q42g6$1ana@newton.cc.rl.ac.uk...
> $file = "c:/directory/file";
>
> $filename =
> substr($file,rindex($file,"/")+1,length($file)-rindex($file,"/"));
Actually, you don't even need all that, because if you leave out the third
parameter for substr it matche sto the end of the string by default:
$filename = substr($file,rindex($file,"/")+1);
Spencer
------------------------------
Date: Thu, 11 Oct 2001 14:27:55 +0200
From: Jean-Philippe Fauvelle <JPFauvelle@Colt-Telecom.fr>
Subject: Re: String manipulation problem
Message-Id: <ht3bstga2kas4ejq69hrs0kp18ehgdsf4m@4ax.com>
Le Thu, 11 Oct 2001 13:50:32 +0200, "Anthony Heuveline" <Anthony.Heuveline@wanadoo.fr> écrit:
>Hi,
>
>I am a newbie in perl so my question should be easy for you to answer... I
>have created a CGI script in perl which allows the user to upload a file
Use the File::Basename module, or a regular expression.
perdoc File::Basename
...
($name,$path,$suffix) = fileparse($fullname,@suffixlist)
fileparse_set_fstype($os_string);
$basename = basename($fullname,@suffixlist);
$dirname = dirname($fullname);
($name,$path,$suffix) = fileparse("lib/File/Basename.pm","\.pm");
fileparse_set_fstype("VMS");
$basename = basename("lib/File/Basename.pm",".pm");
$dirname = dirname("lib/File/Basename.pm");
Jean-Philippe Fauvelle
------------------------------
Date: 11 Oct 2001 10:06:37 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Translate command rare behaviour?
Message-Id: <9q3qvd$rhb$1@mamenchi.zrz.TU-Berlin.DE>
According to Fernando Nieto <fnieto@satec.es>:
> Hello, I've tried the next simple code with "tr" command:
>
> > $line = 'My/name/is: Fran';
> > print "BEF TR: $line\n";
> > $line =~ tr/ \/:/_-=/;
> > print "AFT TR: $line\n";
>
> BEF TR: My/name/is: Fran
> AFT TR: My/name/is: Fran ## doesn't work, no warning nor error ??
>
> > $line = 'My/name/is: Fran';
> > print "BEF TR: $line\n";
> > $line =~ tr/: \//=_-/;
> > print "AFT TR: $line\n";
>
> BEF TR: My/name/is: Fran
> AFT TR: My-name-is=_Fran ## works properly
>
> Anybody now if this is a correct behaviour or why does it happens?
"-" has a special meaning in tr/// , denoting a character range, so
in the first version the right hand side /_-=/ means all characters
whose ASCII[1] values are between that of "_" and that of "=".
But ord( '_') is 95 and ord( '=') is 61, so there are no characters
in that range. You have accidentally specified an empty replacement
list, and tr/// goes on to substitute the searchlist for it. So every
character in the searchlist is replaced by itself and you don't see
any changes.
In the second case, the "-" happens to be the last character of the
replacement list. In this position "-" loses its special meaning
and the replacement list is taken literally.
Use the second version, or escape the "-".
Anno
[1] Well... presumably
------------------------------
Date: 11 Oct 2001 11:10:56 GMT
From: news@roaima.demon.co.uk
Subject: Re: Translate command rare behaviour?
Message-Id: <3bc57030@news.netserv.net>
Fernando Nieto <fnieto@satec.es> wrote:
> Hello, I've tried the next simple code with "tr" command:
>> $line = 'My/name/is: Fran';
>> print "BEF TR: $line\n";
>> $line =~ tr/ \/:/_-=/;
>> print "AFT TR: $line\n";
> BEF TR: My/name/is: Fran
> AFT TR: My/name/is: Fran ## doesn't work, no warning nor error ??
The dash is being interpreted as a range character (from '_' to '=')
not as a literal. Instead, put the dash as the first character, like this:
$line =~ tr/\/ :/-_=/;
Chris
------------------------------
Date: Thu, 11 Oct 2001 13:58:52 +0200
From: Jean-Philippe Fauvelle <JPFauvelle@Colt-Telecom.fr>
Subject: Re: Translate command rare behaviour?
Message-Id: <232bstcgh2ocmungvv1lc8ge1fnr35gerq@4ax.com>
Le 11 Oct 2001 02:25:31 -0700, fnieto@satec.es (Fernando Nieto) écrit:
Maybe the right part ("_=-") is misinterpreted by perl ( '-)' operator ??? ).
When you have a doubt, escape exotic characters.
$line = 'My/name/is: Fran';
print "BEF TR: $line\n";
$line =~ tr# /\:#\_\-\=#;
print "AFT TR: $line\n";
Jean-Philippe Fauvelle
>Hello, I've tried the next simple code with "tr" command:
>
>> $line = 'My/name/is: Fran';
>> print "BEF TR: $line\n";
>> $line =~ tr/ \/:/_-=/;
>> print "AFT TR: $line\n";
>
>BEF TR: My/name/is: Fran
>AFT TR: My/name/is: Fran ## doesn't work, no warning nor error ??
>
>> $line = 'My/name/is: Fran';
>> print "BEF TR: $line\n";
>> $line =~ tr/: \//=_-/;
>> print "AFT TR: $line\n";
>
>BEF TR: My/name/is: Fran
>AFT TR: My-name-is=_Fran ## works properly
>
>Anybody now if this is a correct behaviour or why does it happens?
>
>Thanks so much in advance,
>Fernando
------------------------------
Date: Thu, 11 Oct 2001 19:03:03 +0900
From: tm <tmoero@yahoo.com>
Subject: Re: YOU ARE ALL GAY!
Message-Id: <tmoero-BB8C7C.19030311102001@newsflood.tokyo.att.ne.jp>
Geoffrey Pointer <geoffrey@bigpond.net.au> wrote:
> I realise now how saying too little can sometimes be misconstrued.
>
> > It's funny about that isn't it? Go figure.
>
> This was a comment about the psychobabble in the original message and not
> its subject. Now I can see I also made a joke about the subject. Either
> interpretation is fine by me. I suppose there are others I should now be
> paranoid about. Again. Go figure.
>
hey geof,
What are you mumbling about?
Who are you mumbling at?
Look, if you want to be taken seriously on usenet, read this-
http://www.geocities.com/nnqweb/nquote.html
See if that info will sink into your peabrain. If not, go mumble in some
other ng.
Thanks,
TM
------------------------------
Date: Thu, 11 Oct 2001 06:47:24 -0500
From: alex <aort527@hotmail.com>
Subject: Re: YOU ARE ALL GAY!
Message-Id: <3BC586CC.1C8F108A@hotmail.com>
<tourette>bullshit, crap, damn, faggot.......</tourette>
Adrian Philpott wrote:
> Yeh, reckon I had better go get in the closet so I can come out of it!
------------------------------
Date: 11 Oct 2001 05:53:35 -0700
From: bobh@hslda.org (Robert)
Subject: Re: YOU ARE ALL GAY!
Message-Id: <4a249347.0110110453.726dfe5a@posting.google.com>
How did he know I was an all around jovial guy?
------------------------------
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 1911
***************************************