[15717] in Perl-Users-Digest
Perl-Users Digest, Issue: 3130 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 23 03:05:22 2000
Date: Tue, 23 May 2000 00:05:10 -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: <959065510-v9-i3130@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 23 May 2000 Volume: 9 Number: 3130
Today's topics:
A definition of true? <vsauder@hekimian.com>
Re: A definition of true? <dave@dave.org.uk>
About "sprint f" ? <lee@factory.co.kr>
Re: Basic scripting question <nobody@newsfeeds.com>
Re: Basic scripting question (Andrew Johnson)
Re: Basic scripting question <uri@sysarch.com>
Re: Basic scripting question <anmcguire@ce.mediaone.net>
Re: Basic scripting question <dave@dave.org.uk>
calling sequence of perl scripts <marcl@xs4all.nl>
cut off text after a <br> <lancelotboyle@hotmail.com>
Re: DBM File Limitations? <dave@dave.org.uk>
Re: Help with 500 Internal Server Error <please@no.spam>
Re: join " ", do {$x++}, do {$x++}, do {$x++}; <lr@hpl.hp.com>
Re: Just Beggining Perl Question <jeff@vpservices.com>
New to Perl: Having Issues with Hashes <sjutmp@msn.com>
Re: regexes *sigh* damn I hate these things <nospam@devnull.com>
Re: regexes *sigh* damn I hate these things <Tbone@pimpdaddy.com>
Re: Removing null character padding from the strings Ef <kraja@miel.mot.com>
Re: sorting a list of mixed numbers and text as in perl (Gwyn Judd)
Re: sorting a list of mixed numbers and text as in perl <uri@sysarch.com>
Re: sorting a list of mixed numbers and text as in perl <lr@hpl.hp.com>
Trouble running perlcc baconrad@my-deja.com
Re: valid email address (Philip 'Yes, that's my address' Newton)
Re: valid email address (Philip 'Yes, that's my address' Newton)
What happened to Mail::Internet? <aperrin@davis.DEMOG.Berkeley.EDU>
Re: Windows/Linux Incompatibility (Philip 'Yes, that's my address' Newton)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 22 May 2000 23:50:34 -0400
From: "Vernon Sauder" <vsauder@hekimian.com>
Subject: A definition of true?
Message-Id: <8gcv6i0qbj@enews3.newsguy.com>
This is a multi-part message in MIME format.
------=_NextPart_000_00FB_01BFC448.85679230
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Is there a Perl-recommended way to assign TRUE or FALSE to a variable? I =
thought I saw a comment from Larry on not re-assigning the values TRUE =
and FALSE.
Script:
use strict;
my $var =3D true;
Error:
Bareword "true" not allowed while "strict subs" in use at C:\temp\t.pl =
line 2.
My solution:
my $true =3D 1;
my $false =3D 0;
Any other solutions?
--=20
Vernon Sauder
------=_NextPart_000_00FB_01BFC448.85679230
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type><BASE=20
href=3D"file://C:\Program Files\Common Files\Microsoft =
Shared\Stationery\">
<STYLE>BODY {
BACKGROUND-POSITION: left top; BACKGROUND-REPEAT: no-repeat; COLOR: =
#000000; FONT-FAMILY: Times New Roman; FONT-SIZE: 12pt; MARGIN-LEFT: =
25px; MARGIN-TOP: 25px
}
</STYLE>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR></HEAD>
<BODY bgColor=3D#ffffff>
<DIV>Is there a Perl-recommended way to assign TRUE or FALSE to a =
variable? I=20
thought I saw a comment from Larry on not re-assigning the values TRUE =
and=20
FALSE.</DIV>
<DIV> </DIV>
<DIV>Script:</DIV>
<DIV> use strict;</DIV>
<DIV> my $var =3D true;</DIV>
<DIV> </DIV>
<DIV>Error:</DIV>
<DIV>Bareword "true" not allowed while "strict subs" in use at =
C:\temp\t.pl line=20
2.</DIV>
<DIV> </DIV>
<DIV>My solution:</DIV>
<DIV> my $true =3D 1;</DIV>
<DIV> my $false =3D 0;</DIV>
<DIV> </DIV>
<DIV>Any other solutions?<BR>-- <BR>Vernon Sauder</DIV></BODY></HTML>
------=_NextPart_000_00FB_01BFC448.85679230--
------------------------------
Date: Tue, 23 May 2000 07:53:05 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: A definition of true?
Message-Id: <2fakisgvb9tn2ualv5sba20d5dv0bna6eg@4ax.com>
On Mon, 22 May 2000 23:50:34 -0400, "Vernon Sauder"
<vsauder@hekimian.com> wrote:
>Is there a Perl-recommended way to assign TRUE or FALSE to a variable? I thought I saw a comment from Larry on not re-assigning the values TRUE and FALSE.
>
>Script:
> use strict;
> my $var = true;
>
>Error:
>Bareword "true" not allowed while "strict subs" in use at C:\temp\t.pl line 2.
>
>My solution:
> my $true = 1;
> my $false = 0;
>
>Any other solutions?
Perl doesn't have explicit values for 'true' or 'false'. It defines a
number of scalar values that evaluate as 'false'. All other values
evaluate as 'true'.
The false values are.
* The empty string ''.
* The string '0'
* The number 0
* The undefined value (undef).
If your variable contains any of these four values it will be false,
otherwise it will be true.
Does that help?
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Tue, 23 May 2000 14:03:57 +0900
From: "Lee" <lee@factory.co.kr>
Subject: About "sprint f" ?
Message-Id: <8gd359$bcb$1@news2.kornet.net>
Hi,
I have two questions about sprint f.
$padding_value = $basevalue . ( ' ' x (30-length($basevalue)) );
With above.
1. It seems only count characters not white spaces.
If it is, how can I solve this to count spaces ?
2. If the $basevalue is longer than 30 characters,
How can I cut off the letters at 30 ?
Thanks in advance
------------------------------
Date: Mon, 22 May 2000 21:25:48 -0700
From: Anonymous <nobody@newsfeeds.com>
Subject: Re: Basic scripting question
Message-Id: <392A084C.D258D24B@no.spam>
Uri Guttman wrote:
> and what a shitload of code to do this:
>
> perl -ne 'print unless $. % 3' input_file > output_file
Your code does nothing. Doesn't even have a shebang line. Post code that
loads and runs or don't post.
Stop wasting our time with this crap.
Anonymoose
--------== Posted Anonymously via Newsfeeds.Com ==-------
Featuring the worlds only Anonymous Usenet Server
-----------== http://www.newsfeeds.com ==----------
------------------------------
Date: Tue, 23 May 2000 04:53:33 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Basic scripting question
Message-Id: <h9oW4.15522$95.220223@news1.rdc1.mb.home.com>
In article <392A084C.D258D24B@no.spam>,
Anonymous <nobody@newsfeeds.com> wrote:
> Uri Guttman wrote:
>
> > and what a shitload of code to do this:
> >
> > perl -ne 'print unless $. % 3' input_file > output_file
>
> Your code does nothing. Doesn't even have a shebang line. Post code that
> loads and runs or don't post.
And you, apparently, do not know how to run perl from the command
line. Please see:
perldoc perlrun
> Stop wasting our time with this crap.
oh, and please do that as well.
andrew
--
Andrew L. Johnson http://members.home.net/andrew-johnson/epwp.html
Optimist: The glass is half full.
Pessimist: The glass is half empty.
Engineer: The glass is twice as big as it needs to be.
------------------------------
Date: Tue, 23 May 2000 04:57:47 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Basic scripting question
Message-Id: <x7ya51dfsm.fsf@home.sysarch.com>
>>>>> "A" == Anonymous <nobody@newsfeeds.com> writes:
A> Uri Guttman wrote:
>> and what a shitload of code to do this:
>>
>> perl -ne 'print unless $. % 3' input_file > output_file
A> Your code does nothing. Doesn't even have a shebang line. Post code
A> that loads and runs or don't post. Stop wasting our time with this
A> crap.
hahahahah!!!
it is a shell one-liner purlmoron. it don't need no steeking' shebang!!
go back to your stupid web shit and stop commenting on how to hack
perl. do you even realize why running perl from the command line is even
useful? well, you can't since you only run your crap on some offsite web
server.
and why the other stupid nick? you are already outed and you name and
site are known here. you even siged your name? must be the meds are
wearing off.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Tue, 23 May 2000 00:28:02 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Basic scripting question
Message-Id: <Pine.LNX.4.21.0005230025580.21491-100000@hawk.ce.mediaone.net>
On Mon, 22 May 2000, Anonymous wrote:
+ Uri Guttman wrote:
+
+ > and what a shitload of code to do this:
+ >
+ > perl -ne 'print unless $. % 3' input_file > output_file
+
+ Your code does nothing. Doesn't even have a shebang line. Post code that
+ loads and runs or don't post.
+ Stop wasting our time with this crap.
+
+ Anonymoose
You again?
You know why firewalls are such a pain in the butt? Because they make
it harder to maintain a consistent killfile!!!! Go tell it to
/dev/null.
*plonk*
anm
--
/*-------------------------------------------------------.
| Andrew N. McGuire |
| anmcguire@ce.mediaone.net |
`-------------------------------------------------------*/
------------------------------
Date: Tue, 23 May 2000 07:58:06 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: Basic scripting question
Message-Id: <2takiskge9d0m1v8fqfngkvpouddo903vv@4ax.com>
On Tue, 23 May 2000 02:51:29 GMT, Uri Guttman <uri@sysarch.com> wrote:
>and what a shitload of code to do this:
>
> perl -ne 'print unless $. % 3' input_file > output_file
<pedant>
Actually, Uri, I _think_ you meant
perl -ne 'print if $. % 3' input_file > output_file
</pedant>
hth,
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Tue, 23 May 2000 07:22:25 +0200
From: Marc Lambrichs <marcl@xs4all.nl>
Subject: calling sequence of perl scripts
Message-Id: <392A1591.78F8E27A@xs4all.nl>
I'm calling a perl script in taint mode from a java servlet. This perl
script uses the Expect module for doing a "su root"
> $process = Expect->spawn("su","root");
After handling password and motd I try to call another perl script
> print $process "/usr/local/bin/perl /home/marcl/test.pl"
Now, when I execute the Perl scripts from commandline everything works
fine. Calling it from the servlet only the first Perl script shows up in
my processlist. The second never gets called.
What should I look for?
T.i.a.
Marc
------------------------------
Date: Tue, 23 May 2000 05:18:47 +0100
From: "Lance Boyle" <lancelotboyle@hotmail.com>
Subject: cut off text after a <br>
Message-Id: <8gd106$hvb$1@plutonium.btinternet.com>
Somebody provided a hack below within a perl script to cut off text after
certain amount of characters
if( length( $newstext ) > 256 ) {
$tmpnewshtml = substr( $newstext, 0, 128 );
$tmpnewshtml =~ s/(.*)\s.*/$1/;
$newshtml .= $tmpnewshtml . qq~
However is it possible to modify this to cut off text after a line break
<br> instead ?
I have tried a few combinations though not very successfully.
I hope this is on topic as I don't want to be spanked again (well not in
public anyhow).
------------------------------
Date: Tue, 23 May 2000 07:30:21 +0100
From: Dave Cross <dave@dave.org.uk>
Subject: Re: DBM File Limitations?
Message-Id: <fa9kis4irmj6653bpoio206t1of6scfgpf@4ax.com>
On Mon, 22 May 2000 17:03:19 -0700 (PDT), J Garcia
<garcia868@yahoo.com> wrote:
>I am planning to use DBM file to implement a simple
>database on my site.
>
>How do I find out which DBM format is support by my
>hosting service? Thanks for responding.
You could always use AnyDBM_File which will automatically choose the
best implementation that it can find.
hth,
Dave...
--
<http://www.dave.org.uk> SMS: sms@dave.org.uk
yapc::Europe - London, 22 - 24 Sep <http://www.yapc.org/Europe/>
"There ain't half been some clever bastards" - Ian Dury [RIP]
------------------------------
Date: Tue, 23 May 2000 04:37:00 GMT
From: "Ray Waters" <please@no.spam>
Subject: Re: Help with 500 Internal Server Error
Message-Id: <MVnW4.22234$T41.529073@newsread1.prod.itd.earthlink.net>
B Kemp wrote in message <8gccak$39a$1@barcode.tesco.net>...
>
>>Yup, I'm an old fart but at least I'm still ripping 'em...
>>
>>RW
>
>
>OK and I've been paid for programming for less than a year, but I
learnt
>programming on a TRS80 - in the early 80's.
>and I still go BUG, FIX, BUG, FIX,BUG, FIX, BUG, FIX,BUG, FIX, BUG,
FIX,BUG,
>FIX, BUG, FIX,BUG, FIX, BUG, FIX,BUG, FIX, BUG, FIX,BUG, FIX, BUG,
FIX,BUG,
>FIX, BUG, FIX,BUG, FIX, BUG, FIX,BUG, FIX, BUG, FIX,BUG, FIX, BUG, FIX,
>
Hmmm...maybe that's because the Trash-80's were a bug. <g> Sounds like
your doing it the hard way, trial-and-error. There are easier methods.
I got my little CGI-Perl project up and running today. Seems to work but
needs some hard testing which will be done tomorrow. If all goes well
I'm done start-to-finish in 4 days with the worst problem being the
stupid syntax error I posted about. That's 4 days from never having
written a CGI-Perl script to finished product which includes 8 hefty
scripts with 4 supporting packages with SSL. With available CPAN modules
the majority of the grunt work was a breeze. Basically using (re-using)
available resources like CPAN made it a trivial exercise.
If I had taken the approach of creating a local development environment
to match the target I'd still be working on that instead of getting
coding done and out the door.
The moral of the story is that it is sometimes better to use tools
productively rather than rely on them as a crutch. Ultimately one has to
make code work. Its far easier and more efficient to code correctly
first rather than swipe at it via successive approximation. Understand
the problem and you know the solution...and you get to sleep nights.
RW
------------------------------
Date: Mon, 22 May 2000 23:59:12 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: join " ", do {$x++}, do {$x++}, do {$x++};
Message-Id: <MPG.1393cc183550e5c098aab7@nntp.hpl.hp.com>
In article <8gcstu$2hiq$1@news.enteract.com>, Tbone@pimpdaddy.com says...
> I seem to have lost the ability to RTFM... could someone point me
> to where it says that the above (see subject line) will guarantedly
> produce "1 2 3"?
Nowhere. What makes you think it has too?
Before answering, try to explain the output of this program:
#!/usr/local/bin/perl -w
use strict;
my $x;
print join " ", do {$x++}, do {$x++}, do {$x++};
print "\n";
foo($x, $x++, $x++, $x++);
sub foo { print "@_\n" }
__END__
Output:
0 1 2
6 3 4 5
A firm semantics for Perl would require introducing and elaborating the
'sequence point' concept of ANSI/ISO C.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 22 May 2000 21:27:37 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Just Beggining Perl Question
Message-Id: <392A08B9.95EC2030@vpservices.com>
Jim Kipp wrote:
>
> Hello
> Very new to perl and programming. I am trying to complete an
> exercize in a book.
> I wan to open a file, read into an array, then print 5 lines
> at a time. The user would press enter to see the next five
> lines. I have been trying to figure out the 5 lines at a
> time part, but can't.
>
> open(FILE, ">test.txt");
If you are opening the file for reading, the angle bracket is either
omitted or goes the other direction. And you don't need the double
quotes unless you are using variables. And you might as well give the
filehandle a name that says what it is, and you should always check for
file errors. So, change that line to:
open(IN,'<test.txt') or die "Couldn't open test.txt: $!\n";
> @array = <FILE>;
There's usually no reason to put the file into an array since you can
loop through it with just <FILE>.
> then print 5 lines at a time.
So you set a counter at the top and increment it each time through the
loop, resetting it to 0 when you reach 5.
> The user would press enter to see the next five
> lines.
Reading from Standard input with <STDIN> is terminated with enter so
that's how to do that.
That should be enough hints to get you going. Write back if not.
--
Jeff
------------------------------
Date: Tue, 23 May 2000 00:46:49 -0400
From: "StevenJesseUlbrich" <sjutmp@msn.com>
Subject: New to Perl: Having Issues with Hashes
Message-Id: <sik36aqso1135@news.supernews.com>
I have subroutine, RoutingExtraction, that is passed a string of data.
The subroutine will do a series of REGEX processes and return:
return ($KeyIndex, $GroupNumber, $RowNumber, $AirlineCode, $FlightNumber,
$DepartureAirport, $ArrivalAirport,
$DepartureDate, $DepartureTime, $DTime,$ArrivalDate,
$ArrivalTime, $ATime,
$AirCraft, $ShareCode, $OnTime, $Stops, $FClass, $BClass,
$CClass, $BSegment);
It was my hope that by apply it to a array. It could be handled a little
easier.
The @Routing is assigned by reference to the FlightData hash, but when I
review the contents of the array each entry
only shows the last referenced array X amount of times.
I have tried to review the various source of documentation with any clear
answer. It might be a combination of frustration
and exhaustion.
What I am doing wrong?
Any advice would be appreciated.
Code snippet:
if(/\bRoutingInformation -[0-9]{1,2}\W/){
@Routing = RoutingExtraction(m/RoutingInformation -(.*)/);
$KeyIndex = $KeyBase.@Routing[1];
unshift(@Routing,$KeyIndex); #Add the primary key to the array.
$FlightData{$KeyIndex} = \@Routing;
}
}
foreach $Reference1(keys %FlightData){
#Build a portion of the SQL insert statement
$ArrayElement = $FlightData{$Reference1};
$strTest = join "', '", @$ArrayElement;
$strTest = "'".$strTest."'";
}
print "$strTest\n";
------------------------------
Date: 23 May 2000 05:02:49 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: regexes *sigh* damn I hate these things
Message-Id: <8gd3dp$7v7$0@216.155.33.97>
In article <8gcsp9$2h5v$1@news.enteract.com>, Tbone@pimpdaddy.com
wrote:
| nospam@devnull.com writes:
| >In article <8gca7q$1t42$1@news.enteract.com>, Tbone@pimpdaddy.com
| >wrote:
| >
| > | This bonding is bringing tears to my eyes
| >
| >Yeah yeah yeah, what, you never saw a polite discussion around here
| >before?
|
| You are still reading my posts? That's very irresponsible of you!
| I spoke in confidence that the *plonk* was for real.
I must have missed. Either that or a crash prevented it from being
saved. *shrug*
tone it down or be ignored, I care not which.
| Well, if you are serious, let me quickly make it known that "Godzilla"
Gee, you THINK I might not have seen the GAZILLION other posts
cautioning me to make sure I go over any code that ANYONE posts here
before FULLY IMPLEMENTING IT? you THINK I might FAIL to TEST ANY CODE
THAT *(ANYONE)* POSTS HERE? BEFORE I try and USE IT?
This simplistic caveat applies to EVERYONE here, not just Godzilla.
Get over it.
| is a repressed little weenie with no particular talent except the
| relentlessness that goes with stupidity. The code in those posts is
| not worth analyzing or discussing, so take it as official that you
| have wasted a huge amount of your time with your "polite discussion".
|
| I luckily don't care much about how you feel--still, understand that
| I am not saying the above in order to make you feel stupid. I'd rather
| you did not waste your time with moronic exchanges about useless code.
Let me just say that there are FAR better ways to go about 'not wasting
one's time' and that includes not wasting bandwidth either =:P
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: 23 May 2000 06:23:34 GMT
From: Intergalactic Denizen of Mystery <Tbone@pimpdaddy.com>
Subject: Re: regexes *sigh* damn I hate these things
Message-Id: <8gd856$2bo$1@news.enteract.com>
nospam@devnull.com writes:
> | You are still reading my posts? That's very irresponsible of you!
> | I spoke in confidence that the *plonk* was for real.
>
>I must have missed. Either that or a crash prevented it from being
>saved. *shrug*
I feel your pain.
> | Well, if you are serious, let me quickly make it known that "Godzilla"
>
>Gee, you THINK I might not have seen the GAZILLION other posts
>cautioning me to make sure I go over any code that ANYONE posts here
>before FULLY IMPLEMENTING IT? you THINK I might FAIL to TEST ANY CODE
>THAT *(ANYONE)* POSTS HERE? BEFORE I try and USE IT?
>
>This simplistic caveat applies to EVERYONE here, not just Godzilla.
>
>Get over it.
Get over what?
------------------------------
Date: Tue, 23 May 2000 09:34:18 +0530
From: Rajasankar K <kraja@miel.mot.com>
Subject: Re: Removing null character padding from the strings Efficiently
Message-Id: <392A0342.E48301A5@miel.mot.com>
Uri Guttman wrote:
> also the A unpack format will remove trailing nulls (unlike what the OP
> said):
>
> The "a", "A", and "Z" types gobble just one value, but pack it
> as a string of length count, padding with nulls or spaces as
> necessary. When unpacking, "A" strips trailing spaces and
> nulls, "Z" strips everything after the first null, and "a"
> returns data verbatim.
>
> and depending on the needs, the Z format may work too.
>
Thanks everybody.
The "Z" doesn't work with Perl5.005.
Is this new in Perl5.6?
Raja.
------------------------------
Date: Tue, 23 May 2000 05:19:28 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: sorting a list of mixed numbers and text as in perldoc
Message-Id: <slrn8impn2.81p.tjla@thislove.dyndns.org>
I was shocked! How could The WebDragon <nospam@devnull.com>
say such a terrible thing:
>In article <slrn8il7nt.5tv.tjla@thislove.dyndns.org>, tjla@guvfybir.qlaqaf.bet
>(Gwyn Judd) wrote:
>
> | ewww you found a bug :). looks like the "text_first" thingy only works
> | correctly when we try to sort the numbers in reverse order, otherwise we
> | have to reverse the sense of it. It's not a very well named variable
> | either. oh well I am only an egg.
>
>'only an egg' LOL :D good book.
>
>well, try THIS puppy on for size. I would like to come up with a way to sort a
>list of the map-names for Unreal Tournament that get submitted to the site I do
>reviews for.. and there are some who put numbers or [] type characters in the
>filenames to make it sort higher (a big no-no).
>
>The main admin of the site has to manually do his listing of these to force them
>to the bottom of the list instead (evil grin), but since I patched together a
>little cgi/perl script to work with this listing more flexibly, the sorting
>breaks and I have to let 'scum' rise to the top.
>
>I tried some of the map names in this script instead of the simple words that
>were listed here, and got some _really_ weird results
no this is a feature not a bug :). oh all right it's a bug. What happens
is it gives the "numerical value" of any text containing a number
*anywhere* in the string to that string. ie. the string "the2ofus" gets
the "numerical value" 2 rather than being considered text. It's not
immediately clear what the best way to fix this is though. What if you
wanted strings containing numbers to be considered numerical? I am
thinking in your case you want to sort any strings *containing* numbers
as strings, not as numbers. In that case this may work:
#!/usr/bin/perl -w
use POSIX qw(INT_MAX);
@old = qw(DM-007Archives DM-007Stack DM-1 DM-88][ DM-Abandoned DM-LongestYard][
DM-Concussion DM-Psykosis][ DM-Way2to4 DM-Zyklotron DM-[tech]labyrinth
DM-ForwardThrust DM-Gemetzel DM-[tech]labyrinth2);
$numbers_ascending = 1;
$text_ascending = 1;
$text_first = 1;
$text_val = [[-1,1],[1,-1]]->[$numbers_ascending][$text_first] * INT_MAX;
@new = map { $_->[0] }
sort { ($a->[1] <=> $b->[1]) * ($numbers_ascending ? 1 : -1)
||
($a->[2] cmp $b->[2]) * ($text_ascending ? 1 : -1)
} map { [$_, m/^(\d+)$/ ? $1 : $text_val, uc($_)] } @old;
$count = scalar(@old);
for ($i=0; $i < $count; $i++) {
print "old = $old[$i]\n", '.' x 50, "new = $new[$i]\n";
}
exit;
except this goes and sorts individual digits before corresponding digits
old = DM-007Archives
..................................................new = DM-007Archives
old = DM-007Stack
..................................................new = DM-007Stack
old = DM-1
..................................................new = DM-1
old = DM-88][
..................................................new = DM-88][
old = DM-Abandoned
..................................................new = DM-Abandoned
old = DM-LongestYard][
..................................................new = DM-Concussion
old = DM-Concussion
..................................................new = DM-ForwardThrust
old = DM-Psykosis][
..................................................new = DM-Gemetzel
old = DM-Way2to4
..................................................new = DM-LongestYard][
old = DM-Zyklotron
..................................................new = DM-Psykosis][
old = DM-[tech]labyrinth
..................................................new = DM-Way2to4
old = DM-ForwardThrust
..................................................new = DM-Zyklotron
old = DM-Gemetzel
..................................................new =
DM-[tech]labyrinth
old = DM-[tech]labyrinth2
..................................................new =
DM-[tech]labyrinth2
I think what you need is a compare function a bit like "cmp" except it
sorts digits after characters. Anyone know of such a thing or will we
have to end up writing one ourself?
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
It's not so hard to lift yourself by your bootstraps once you're off the ground.
-- Daniel B. Luten
------------------------------
Date: Tue, 23 May 2000 05:38:43 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: sorting a list of mixed numbers and text as in perldoc
Message-Id: <x7vh05ddwe.fsf@home.sysarch.com>
>>>>> "GJ" == Gwyn Judd <tjla@guvfybir.qlaqaf.bet> writes:
GJ> is it gives the "numerical value" of any text containing a number
GJ> *anywhere* in the string to that string. ie. the string "the2ofus" gets
GJ> the "numerical value" 2 rather than being considered text. It's not
huh? what planet are you from? 'the2ofus' in a numerical context is 0,
not 2.
GJ> I think what you need is a compare function a bit like "cmp"
GJ> except it sorts digits after characters. Anyone know of such a
GJ> thing or will we have to end up writing one ourself?
you obviously don't understand sorting. there are many ways to sort
multiple fields including the ST and the GRT. you just have to order the
fields in the priority you needs. it has nothing to do with sorting
numbers after text with a rewrite of cmp.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Mon, 22 May 2000 23:33:34 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: sorting a list of mixed numbers and text as in perldoc
Message-Id: <MPG.1393c61aa6ceb04498aab6@nntp.hpl.hp.com>
In article <8gcltg$4mr$0@216.155.33.26>, nospam@devnull.com says...
> In article <MPG.139311bb8e56dbbd98aaac@nntp.hpl.hp.com>, Larry Rosler
> <lr@hpl.hp.com> wrote:
>
> | #!/usr/local/bin/perl -w
> | use strict;
> |
> | my @unsorted = qw[hi low 1 2 3 yo what's up dawg?];
> |
> | my @sorted = map substr($_, 1 + rindex $_, "\0") => sort
> | map { (/(\d+)/ ? 0 . pack N => $1 : 1 . uc) . "\0$_" } @unsorted;
> |
> | print "@unsorted\n@sorted\n";
> |
>
> Larry, this still results in
> ====
> hi low 1 2 3 yo what's up dawg?
> 1 2 3 dawg? hi low up what's yo
> ====
Indeed it does, because that is what I presumed the spec to be. If you
want something else, figure out how to take what you see, understand how
it works, and adapt it for your own needs. That's called learning how to
program, instead of learning how to be spoon-fed.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 23 May 2000 06:04:56 GMT
From: baconrad@my-deja.com
Subject: Trouble running perlcc
Message-Id: <8gd723$sp8$1@nnrp1.deja.com>
I am having a hell of a time getting perlcc to work at all. I am using
the simplest possible "hello world" code. Any help is greatly
appreciated.
Following is what I think is all pertinent information.
OS:Windows 98
Perl: ActiveState perl build 613 for perl v5.6.0 (upgraded for running
perlcc)
C compiler: MS Visual C++ 6.0 (installed to do perlcc)
Environment: Added C++ bin directory to path, ran vcvars32.bat
Location: In my own c:\PerlTest directory (though I have tried others)
Code: 1 line, print("Hello World");
Command: perlcc hello.pl
Following is the output I get:
------------------------------------------------------------------------
--------
Compiling hello.pl:
------------------------------------------------------------------------
--------
Making C(hello.pl.c) for hello.pl!
C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. -MB::Stash -
c hello.pl
hello.pl syntax OK
C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. -MO=C,-l2000,
hello.pl
hello.pl syntax OK
#ifdef BROKEN_STATIC_REDECL
#define Static extern
#else
#define Static static
#endif /* BROKEN_STATIC_REDECL */
#ifdef BROKEN_UNION_INIT
/*
* Cribbed from cv.h with ANY (a union) replaced by void*.
* Some pre-Standard compilers can't cope with initialising unions. Ho
hum.
*/
typedef struct {
char * xpv_pv; /* pointer to malloced string */
STRLEN xpv_cur; /* length of xp_pv as a C string */
STRLEN xpv_len; /* allocated size */
IV xof_off; /* integer value */
double xnv_nv; /* numeric value, if any */
MAGIC* xmg_magic; /* magic for scalar array */
HV* xmg_stash; /* class package */
HV * xcv_stash;
OP * xcv_start;
OP * xcv_root;
void (*xcv_xsub) (CV*);
void * xcv_xsubany;
GV * xcv_gv;
char * xcv_file;
long xcv_depth; /* >= 2 indicates recursive call */
AV * xcv_padlist;
CV * xcv_outside;
#ifdef USE_THREADS
perl_mutex *xcv_mutexp;
struct perl_thread *xcv_owner; /* current owner thread */
#endif /* USE_THREADS */
cv_flags_t xcv_flags;
} XPVCV_or_similar;
#define ANYINIT(i) i
#else
#define XPVCV_or_similar XPVCV
#define ANYINIT(i) {i}
#endif /* BROKEN_UNION_INIT */
#define Nullany ANYINIT(0)
#define UNUSED 0
#define sym_0 0
static int ()
{
dTHR;
dTARG;
djSP;
return 0;
}
ERROR: In generating code for hello.pl!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 23 May 2000 05:06:54 GMT
From: nospam.newton@gmx.li (Philip 'Yes, that's my address' Newton)
Subject: Re: valid email address
Message-Id: <392a0158.555149903@news.nikoma.de>
On Sun, 21 May 2000 20:34:40 GMT, "The Evil Beaver"
<evilbeaver.picksoft@NOSPAMzext.net> wrote:
>Philip 'Yes, that's my address' Newton <nospam.newton@gmx.li> wrote...
>> No, since there's no $ at the end of the regex. But won't match, for
>> example, one-letter domain elements such as x.org.
>
>Well, Jennifer stated "I'm thinking that if it isn't
>any_char@any_two_char.any_two_char
>that it isn't valid syntax." which says right there to avoid x.org or any
>other one letter sld.
And she was wrong with that thought, since it *is* valid syntax.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 23 May 2000 05:06:55 GMT
From: nospam.newton@gmx.li (Philip 'Yes, that's my address' Newton)
Subject: Re: valid email address
Message-Id: <392a022d.555363460@news.nikoma.de>
On Sun, 21 May 2000 17:55:28 -0700, John Springer <john@digitalmx.com>
wrote:
>if ($email =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(\.$)/ ||
> ($email !~ /^.+\@localhost$/ &&
> $email !~ /^.+\@\[?(\w|[-.])+\.[a-zA-Z]{2,3}$/)) {
I'd be interested to learn: why you escape the at sign in the second and
third line, but not in the first; why you use \[? (probably to allow
[127.0.0.1] type IP addresses?) but no \]? ; why you write '(\w|[-.])+'
rather than [\w.-]+ .
Note also that a dot isn't strictly necessary after the at sign. I've
seen an address of the form somebody@cx, who worked (so I'm told) for
the Christmas Islands NIC. Compare `nslookup -q=mx cx` (or `dig cx mx`).
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 22 May 2000 22:44:40 -0700
From: Andrew Perrin - Demography <aperrin@davis.DEMOG.Berkeley.EDU>
Subject: What happened to Mail::Internet?
Message-Id: <u5khfbprfav.fsf@davis.DEMOG.Berkeley.EDU>
I can't find it on cpan or activestate.
ap
--
---------------------------------------------------------------------
Andrew J. Perrin - aperrin@demog.berkeley.edu - NT/Unix Admin/Support
Department of Demography - University of California at Berkeley
2232 Piedmont Avenue #2120 - Berkeley, California, 94720-2120 USA
http://demog.berkeley.edu/~aperrin --------------------------SEIU1199
------------------------------
Date: Tue, 23 May 2000 05:06:56 GMT
From: nospam.newton@gmx.li (Philip 'Yes, that's my address' Newton)
Subject: Re: Windows/Linux Incompatibility
Message-Id: <392a03a6.555739982@news.nikoma.de>
On Sun, 21 May 2000 23:50:50 -0400, "Brian Landers"
<brian@bluecoat93.org> wrote:
>You might try stripping control-M characters as you read the prefs file.
>Windows files have different end-of-line markers than UNIX files. This could
>be causing problems. I don't believe chomp() will strip both the control-M
>and the \n.
It will if you set $/ properly -- to "\cM\cJ" in this case. (Or
"\015\012" or "\r\n".)
However, note that it doesn't do regexes -- if some lines end in \r\n
and some in \n, you can't set $/ to "\r?\n". But if all lines end in
CRLF instead of just LF, you can get by with changing $/ -- though I'd
change the source file instead (for example with `perl -i.bak -p -e
'tr/\r//d' basepref.txt` or similar, or :1,$s/^V^M// in vi).
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3130
**************************************