[24522] in Perl-Users-Digest
Perl-Users Digest, Issue: 6702 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 17 21:05:43 2004
Date: Thu, 17 Jun 2004 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 Thu, 17 Jun 2004 Volume: 10 Number: 6702
Today's topics:
Re: 'my' doesn't totally isolate <emschwar@pobox.com>
how to determine whether variable is a scalar or an arr <superdoehli_nospam@gmx.at>
Re: how to determine whether variable is a scalar or an <ittyspam@yahoo.com>
Re: how to determine whether variable is a scalar or an <noreply@gunnar.cc>
Re: How to launch VFP from perl <usenet@morrow.me.uk>
Re: instance of class into sub? <kkeller-usenet@wombat.san-francisco.ca.us>
KeepCDATA => 1 in XML::DOM <markus.mohr@mazimoi.de>
Re: KeepCDATA => 1 in XML::DOM <mgjv@tradingpost.com.au>
Re: Net::SMTP problem <ittyspam@yahoo.com>
Re: pattern match problem <noreply@gunnar.cc>
Perl and Sun Grid Engine (SGE) (Leo)
Re: Perl and Sun Grid Engine (SGE) <usenet@morrow.me.uk>
Re: random underslashes and single regex <pinyaj@rpi.edu>
Re: random underslashes and single regex <pinyaj@rpi.edu>
Re: SMS using perl - how? <Lizzie_member@newsguy.com>
Re: SMS using perl - how? <lv@aol.com>
Re: sorting text jamasd@hotmail.com
Re: sorting text <ittyspam@yahoo.com>
Re: sorting text <noreply@gunnar.cc>
Re: sorting text <noreply@gunnar.cc>
Re: Structure of complex distributions <usenet@morrow.me.uk>
Why won't this split file script work? <max@NOSPAMkipness.com>
Re: Why won't this split file script work? <odyniec-usenet@odyniec.net>
Re: Why won't this split file script work? <pinyaj@rpi.edu>
Re: Why won't this split file script work? <krahnj@acm.org>
Re: Why won't this split file script work? (Thomas Church)
Re: Why won't this split file script work? (Thomas Church)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 17 Jun 2004 13:34:22 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: 'my' doesn't totally isolate
Message-Id: <eto3c4uf075.fsf@fc.hp.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> "defined(@aaa)" is deprecated, unreliable, non-portable and subject
> to change without notice. Okay? Okay.
You forgot the nasal demons.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Thu, 17 Jun 2004 22:13:03 +0200
From: Alex <superdoehli_nospam@gmx.at>
Subject: how to determine whether variable is a scalar or an array?
Message-Id: <MPG.1b3c19bb7eb588c6989680@news.inode.at>
I need the perl equivalent to a function like PHP's is_array() to check
the type of a perl variable.
Imagine this:
Let's define an array which can be either
@arr = (1, 2, 3);
or
@arr = ( [ 1, 2], [3, 4], [5, 6] );
ie, a list or an array of arrays (strictly speaking, a list of array
references).
Now I want to dump the array (whether it is a list or an array of
arrays) with a code block like this:
-----------------------------------------
for $element ( @arr) {
if (UNKNOWN TEST FOR SCALARITY) {
# one dimensional list
print "next scalar: $element\n";
} else {
# two dimensional list
print "next list of elements: (";
for $e (@$element) {
print "$e, ";
}
print")\n";
}
}
-----------------------------------------
My problem: which functionality provides the information whether
$element is a scalar or a reference to an array which in turn contains
the elements of interest? This functionality should replace the string
"UNKNOWN TEST FOR SCALARITY".
In PHP this would be is_array() or is_string() or is_xxxx...:
if (is_array($element)) {
print "is an array";
} else {
print "is a scalar";
}
And in Perl?
Alex
------------------------------
Date: Thu, 17 Jun 2004 16:16:37 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: how to determine whether variable is a scalar or an array?
Message-Id: <20040617161616.H20623@dishwasher.cs.rpi.edu>
On Thu, 17 Jun 2004, Alex wrote:
> I need the perl equivalent to a function like PHP's is_array() to check
> the type of a perl variable.
perldoc -f ref
------------------------------
Date: Fri, 18 Jun 2004 00:57:12 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how to determine whether variable is a scalar or an array?
Message-Id: <2jelueF1103diU1@uni-berlin.de>
Alex wrote:
> which functionality provides the information whether $element is a
> scalar or a reference to an array which in turn contains the
> elements of interest?
Paul answered your question. I would replace
if (UNKNOWN TEST FOR SCALARITY) {
with
unless (ref $element) {
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 18 Jun 2004 00:15:52 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How to launch VFP from perl
Message-Id: <catc7o$9tc$1@wisteria.csv.warwick.ac.uk>
Quoth mfzarno@nsa.gov (zeke):
> Bill <wherrera@lynxview.com> wrote in message news:<HaidnTSsMY-HWlLdRVn-sA@adelphia.com>...
> > zeke wrote:
> > > I have a VisualFoxPro program (.fxp extension) that I wish my perl
> > > script to launch. In addition I need to pass an argument from perl to
> > > the VFP program, and lastly receive back from the VFP program an
> > > argument (successful vs error condition at end of VFP program). I can
> > > do this in Mac environment, but am now required to do same in
> > > Windows2000PRO
> >
> > If you would post the part of the script that is Mac-specific in its
> > call of VFP, we could probably help you port it.
>
> OK. I have a VFP program called "TEST01.FXP" in directory
> /Volumes/INWORK. I have a crontab entry to call "TEST1.PL" at 6 A.M.
> daily. The "TEST1.PL" script is:
>
> #! /usr/bin/perl
>
> `open "/Volumes/INWORK/TEST01.FXP"`;
Try
`c:/path/to/vfp.exe c:/path/to/test01.fxp`
or perhaps
`start c:/path/to/test01.fxp`
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: Thu, 17 Jun 2004 12:40:51 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: instance of class into sub?
Message-Id: <34ssac.b5h.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2004-06-17, gep <98734@mail.muni.cz> wrote:
> I dont think so, because he will help people, who read only one of the
> newsgs. The same situation could appear, when somebody writes sth. and
> then he posts it and then he finds out, that the same answer is there
> yet, because sb else...
When you appropriately crosspost, everyone who reads *at least one*
of the newsgroups will see the message, and (crossposted) answers, exactly
once. When you multipost, everyone who reads n of the multiposted
newsgroups will see the message n times. That's fine for those whom
n==1, but increasinly irritating for those when n>1.
So, if you feel you must reach multiple newsgroups, crosspost. If you
don't know how to crosspost, *don't* multipost (making one post in one
group, then making the same or similar post in another). If you do
multipost, expect an exponentially decreasing amount of help from people
who read more than one of the groups to which you post.
- --keith
- --
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQFA0fPChVcNCxZ5ID8RAv6lAJ9xFhLEa+U7SVqo7eOnRagO6uCINgCdEMoo
kXrIoXmAXLU5mGAAcW9s+Lg=
=qG7V
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 17 Jun 2004 22:47:38 +0200
From: Markus Mohr <markus.mohr@mazimoi.de>
Subject: KeepCDATA => 1 in XML::DOM
Message-Id: <hp04d05pvme9akj02f4b2qnot4rusb86h0@4ax.com>
Hi, all,
is it possible that "KeepCDATA => 1" within XML::DOM (e. g. 1.43) does
not work properly?
Sincerely
Markus Mohr
------------------------------
Date: 17 Jun 2004 23:01:25 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: KeepCDATA => 1 in XML::DOM
Message-Id: <slrncd48m4.m2o.mgjv@verbruggen.comdyn.com.au>
[Please, do not post the same message to two newsgroups independently.
You also posted this to comp.lang.perl.modules. Instead, use your
newsreader's crossposting facility to post to multiple groups]
On Thu, 17 Jun 2004 22:47:38 +0200,
Markus Mohr <markus.mohr@mazimoi.de> wrote:
> Hi, all,
>
> is it possible that "KeepCDATA => 1" within XML::DOM (e. g. 1.43) does
> not work properly?
It is possible, although I'd rate it as unlikely. What makes you think
it doesn't work? Where is the code that you tested, and where is the
data you tested it with? If you post a small self-contained code
example and XML document here, we can have a look at it for you.
Otherwise, we can't.
Martien
--
|
Martien Verbruggen | This matter is best disposed of from a great
Trading Post Australia | height, over water.
|
------------------------------
Date: Thu, 17 Jun 2004 14:18:11 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Net::SMTP problem
Message-Id: <20040617141350.T20623@dishwasher.cs.rpi.edu>
On Thu, 17 Jun 2004, Bob wrote:
> >>Does anybody know why it is failing and is there any way to see exactly
> >>what is being sent to the mail server?
> >
> >
> >
> > Run your script with warnings enabled, and Perl will tell you exactly
> > what's wrong with the first two lines of this code.
>
> Ok, I turned on warnings:
> $smtp->mail( "b\@my.domain" );
> $smtp->recipient( "b2\@my.domain" );
> $msg_contents = "t";
>
> Now it is a postfix question:
> reject: RCPT from unknown[192.168.1.100]
I'll give you the benefit of the doubt for now and assume that you're not
trying to attack other mail servers or do otherwise illegal and/or immoral
things...
I *believe* this message is generated when the mail server disallows a
machine from emailing via that server. In other words, you can generally
only contact your own SMTP server to send mail. (If your ISP is
nycap.rr.com, for example, you should only be trying to use
smtp.nycap.rr.com). Most mail servers will prevent users not on their own
network from using their mail servers.
I could be completely wrong in my diagnosis, however. Perhaps you should
try posting an actual complete program, with real values, as suggested by
those same posting guidelines I previously suggested you read.
If I'm not wrong, then this is really not a Perl topic any longer, and
should be moved to a more appropriate newsgroup (ie, one that deals with
SMTP instead of a particular programming language).
Paul Lalli
------------------------------
Date: Fri, 18 Jun 2004 01:36:17 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: pattern match problem
Message-Id: <2jeo7nFv90knU1@uni-berlin.de>
Brian McCauley wrote:
> "Lex" <nospam@peng.nl> writes:
>> What I actually want a script to do is the following:
>>
>> look for <pre> and </pre> and erase all the <br> that you find
>> within it, no matter what you find. However: leave the rest! (
>> linebreaks etc.)
>>
>> But I don't know how to do it properly.
>
> Use an HTML parser module.
>
>> I tried doing this:
>>
>> $rec{'Text'} =~ s%<pre>(.*?)<br>(.*?)</pre>%<pre>$1 $2</pre>%gim;
>
> Do not attempt to process HTML using just regex - it simply isn't
> worth the effort.
That's too categoric IMO. This problem appears to be rather limited,
and under certain conditions, the OP's need may well be served through
something like this:
$rec{'Text'} =~ s{(<pre.*?>.+?</pre>)}{
(my $rest = $1) =~ s/<br.*?>//gis;
$rest
}egis;
To the OP: Please study the FAQ:
perldoc -q "remove HTML"
and consider whether using the s/// operator like above would be
'safe' enough for your case.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 17 Jun 2004 14:55:44 -0700
From: lxh4info@yahoo.com (Leo)
Subject: Perl and Sun Grid Engine (SGE)
Message-Id: <25606b19.0406171355.1067d340@posting.google.com>
Dear all,
I'm writing code to run on a cluster machine. Basically I need to run
a Perl program 200 times and each time generate a line of the output.
I use a C-shell script to call the perl progam and distribute it
through Sun Grid Engine(SGE) to the nodes of the cluster (because SGE
only takes shell script). My have two implementations: (1) write the
output into different files (2) append the output to a single file.
Obviously the first approach is not efficient. But for the second one,
I've only got less than 200 results(120-180 output lines). My
questions are: (1) is this the problem with the deadlock when writing
files? if so, how perl handle this issue? (like the one in C, means I
have to write my own code to deal with the situation?) (2) Or SGE has
the ability to not allow the file-writing at the same time? I hope
someone can explain this to me and I would appreciate your help!
Thanks.
Leo
------------------------------
Date: Fri, 18 Jun 2004 00:30:58 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl and Sun Grid Engine (SGE)
Message-Id: <catd41$9tc$3@wisteria.csv.warwick.ac.uk>
Quoth lxh4info@yahoo.com (Leo):
>
> I'm writing code to run on a cluster machine. Basically I need to run
> a Perl program 200 times and each time generate a line of the output.
> I use a C-shell script to call the perl progam and distribute it
> through Sun Grid Engine(SGE) to the nodes of the cluster (because SGE
> only takes shell script). My have two implementations: (1) write the
> output into different files (2) append the output to a single file.
> Obviously the first approach is not efficient. But for the second one,
> I've only got less than 200 results(120-180 output lines). My
> questions are: (1) is this the problem with the deadlock when writing
> files? if so, how perl handle this issue? (like the one in C, means I
> have to write my own code to deal with the situation?)
I'm not sure what you mean by 'deadlock', but the answer is that you
need to lock the files you are using. As the files are (presumably) on
nfs, you will need to use fcntl rather than flock locking.
Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
------------------------------
Date: Thu, 17 Jun 2004 14:07:30 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: random underslashes and single regex
Message-Id: <Pine.SGI.3.96.1040617140521.325267A-100000@vcmr-64.server.rpi.edu>
On 17 Jun 2004, Bill wrote:
>Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2jcp83Fvb6bpU1@uni-berlin.de>...
>
>> >
>> > It is for a mail filter: a spammer mutates the From by moving a _
>> > character at random.
>>
>> Aha, thanks, but I meant why are you anxious to do it in one
>> statement? To me, using tr/// to remove it seems both more straight
>> forward and more efficient.
>
>Yes, probably, but the underlying program wants a list of regexp.
>
>The replies I have seen tend to support a suspicion of mine: _regular_
>expressions have problems dealing with even minor amounts of truly
>_random_ variation. I guess that is probably due to the fact they deal
>with regularities :).
Yeah. Here's an irregular expression:
if (subset("alphabet", "ape", my($extra)) {
print "'ape' + '$extra' = 'alphabet'\n";
}
# or
# my $is_subset = subset("alphabet", "ape");
sub subset {
$_[0]=~/^(?{[("")x2]})(.*)(?{[$^R->[0].$1,$^R->[1]]})(?:(
.)(?{[$^R->[0],$^R->[1].$2]})(.*)(?{[$^R->[0].$3,$^R->[1]
]}))*\z(?(?{$^R->[0]eq$_[1]})(?{$_[2]=$^R->[1]})|(?!))/sx
}
It works with Perl 5.8.4; before that I can't be sure.
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Thu, 17 Jun 2004 20:15:17 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: random underslashes and single regex
Message-Id: <Pine.SGI.3.96.1040617201212.328910A-100000@vcmr-64.server.rpi.edu>
On Thu, 17 Jun 2004, Jeff 'japhy' Pinyan wrote:
>On 17 Jun 2004, Bill wrote:
>
>>The replies I have seen tend to support a suspicion of mine: _regular_
>>expressions have problems dealing with even minor amounts of truly
>>_random_ variation. I guess that is probably due to the fact they deal
>>with regularities :).
>
>Yeah. Here's an irregular expression:
>
> if (subset("alphabet", "ape", my($extra)) {
> print "'ape' + '$extra' = 'alphabet'\n";
> }
> # or
> # my $is_subset = subset("alphabet", "ape");
>
> sub subset {
> $_[0]=~/^(?{[("")x2]})(.*)(?{[$^R->[0].$1,$^R->[1]]})(?:(
> .)(?{[$^R->[0],$^R->[1].$2]})(.*)(?{[$^R->[0].$3,$^R->[1]
> ]}))*\z(?(?{$^R->[0]eq$_[1]})(?{$_[2]=$^R->[1]})|(?!))/sx
> }
It's not just a "subset", it's a subset in order. Anyway, here are three
functions that do the same thing (as subset() above). The first is the
above, the other two are variations. in1() is the slowest, in3() is the
fastest. They're all the same number of bytes. Creepy. (I worked them
that way -- I know they can be golfed shorter, but I wanted all of them to
be the same length, and to be a nice rectangle.)
sub in1 {
$_[0]=~/^(?{[("")x2]})(.*)(?{[$^R->[0].$1,$^R->[1]]})(?:(
.)(?{[$^R->[0],$^R->[1].$2]})(.*)(?{[$^R->[0].$3,$^R->[1]
]}))*\z(?(?{$^R->[0]eq$_[1]})(?{$_[2]=$^R->[1]})|(?!))/sx
}
sub in2 {
@_=(our$i=\$_[2],@_);my$R;$R=qr/(?{substr$_[2],$%,1,''})(
(??{''ne$^R&&"[^\Q$^R\E]*\Q$^R"}))(?{''ne$^R&&chop($$i.=$
1);$^R})(??{''ne$^R&&$R})(.*)(?{$$i.=$2})/sx;$_[1]=~/^$R/
}
sub in3 {
@_=(our$i=\$_[2],@_);$_[1]=~m{\A(?>\z|(?{"\Q@{[substr$_[2
],0,1,'']}"})((??{"[^$^R]*$^R"}))(?{''ne$1&&chop($$i.=$1)
})(?(?{$_[2]eq''})(?{$$i.=$'}).*))+(?(?{$_[2]ne''}).^)}xs
}
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 17 Jun 2004 11:37:34 -0700
From: Lizzie <Lizzie_member@newsguy.com>
Subject: Re: SMS using perl - how?
Message-Id: <casode01tqp@drn.newsguy.com>
Hello,
>
>How can I send an SMS message to my mobile phone using perl???
>Is there any FREE gateway for sending SMS?
You could try a third party party application to handle the sending rather than
trying to code all of it yourself. Have a look at PageGate
http://www.notepage.net/pagegate.htm
Details on how to integrate PageGate into existing apps are at -
http://www.notepage.net/how-to-integrate.htm
Lizzie L
------------------------------
Date: Thu, 17 Jun 2004 19:50:52 -0500
From: l v <lv@aol.com>
Subject: Re: SMS using perl - how?
Message-Id: <40d23cdc$1_5@corp.newsgroups.com>
Neo wrote:
> Hi,
>
> How can I send an SMS message to my mobile phone using perl???
> Is there any FREE gateway for sending SMS?
>
> Thnx!
> -Neo
>
>
Have you tried sending you an SMTP email to your phone number (including
area code) @<provider>. For example, I have Verizon so I send to
xxxxxxxxxx@vtext.com
Len
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
------------------------------
Date: 17 Jun 2004 11:52:27 -0700
From: jamasd@hotmail.com
Subject: Re: sorting text
Message-Id: <3151a273.0406171052.42c5d558@posting.google.com>
jamasd@hotmail.com wrote in message news:<3151a273.0406161237.77234f3a@posting.google.com>...
I tried running this program and it comes up with an error. What part
of it is incorrect:
use strict;
use warnings;
my ( $buffer , @fields , $filename , %hash1 );
$filename = 'C:\Documents and Settings\vhlab\Desktop\doc.txt';
open(INPUT,"<$filename") or
die("Can't open file \"$filename\" : $!\n");
%hash1 = ( "ytkyk" => 1 , "ghjhg" => 1 );
while ( $buffer = <INPUT> ) {
chomp $buffer;
@fields = split(/\t+/,$buffer);
if ( 2 < @fields ) { # Ignore if less than 3 fields
next;
}
unless ( exists $hash1{$fields[2]} ) {
next;
} print "$buffer\n";
}
close INPUT;
Thank you.
------------------------------
Date: Thu, 17 Jun 2004 15:11:40 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: sorting text
Message-Id: <20040617150901.N20623@dishwasher.cs.rpi.edu>
On Thu, 17 Jun 2004 jamasd@hotmail.com wrote:
> jamasd@hotmail.com wrote in message news:<3151a273.0406161237.77234f3a@posting.google.com>...
>
> I tried running this program and it comes up with an error. What part
> of it is incorrect:
>
> use strict;
> use warnings;
>
> my ( $buffer , @fields , $filename , %hash1 );
>
> $filename = 'C:\Documents and Settings\vhlab\Desktop\doc.txt';
> open(INPUT,"<$filename") or
> die("Can't open file \"$filename\" : $!\n");
>
> %hash1 = ( "ytkyk" => 1 , "ghjhg" => 1 );
>
> while ( $buffer = <INPUT> ) {
> chomp $buffer;
> @fields = split(/\t+/,$buffer);
> if ( 2 < @fields ) { # Ignore if less than 3 fields
> next;
> }
This doesn't do what the comment says it does. This ignores if more than
2 fields. Is that the problem you're talking about?
> unless ( exists $hash1{$fields[2]} ) {
> next;
> } print "$buffer\n";
> }
> close INPUT;
>
We're not mind readers. What error, exactly, did it come up with? (Also,
please attempt to properly indent your code when posting. If your news
reader program is mangling the whitespace, consider getting a better news
reader).
Paul Lalli
------------------------------
Date: Thu, 17 Jun 2004 21:35:43 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: sorting text
Message-Id: <2jea4jF10rt04U1@uni-berlin.de>
jamasd@hotmail.com wrote:
> I tried running this program and it comes up with an error.
What kind of error? If you mean that it runs *without* errors or
warnings, even if it doesn't print anything, you should have said so
to make it easier to help you.
> What part of it is incorrect:
<snip>
> if ( 2 < @fields ) { # Ignore if less than 3 fields
Suppose you mean:
if ( 3 > @fields ) {
or something like it.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 17 Jun 2004 22:38:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: sorting text
Message-Id: <2jedptF107b39U1@uni-berlin.de>
jamasd@hotmail.com wrote to comp.lang.perl.modules:
> Here is a sample of my data (each column is separated by tabs):
What the h... Yesterday you posted the same question to
comp.lang.perl.misc, and several people have helped you. Why are you
repeating the original question now in comp.lang.perl.modules??? (And
how is your question related to the use of Perl modules?)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 18 Jun 2004 00:21:57 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Structure of complex distributions
Message-Id: <catcj5$9tc$2@wisteria.csv.warwick.ac.uk>
Quoth kj <socyl@987jk.com>:
>
> I am working on a pretty complex distribution, and I could use some
> advice on how to structure its directories.
This depends on what you are using to install the distro. For something
this complicated, I would recommend Module::Build, which prefers you to
put things under lib/:
lib/A.pm
lib/A/X.pm
lib/A/X.xs
etc.
> Other scripts are code-generating *.pl.PL scripts. The resulting
> *.pl scripts are part of what is ultimately installed.
If you tell Module::Build about these it will run them and install the
results for you.
> [1] I have seen many cases in which, e.g., Foo.xs file is placed
> at the top of the distro, while the corresponding Foo.pm (which
> defines the package Bar::Baz::Foo) is placed either in $TOP_OF_DISTRO
> or in $TOP_OF_DISTRO/lib/Bar/Baz. I get the impression that there
> is something against putting Foo.xs in $TOP_OF_DISTRO/lib/Bar/Baz.
> Is this the case, and why? The cases in which Foo.pm is put in
> $TOP_OF_DISTRO, right alongside Foo.xs, and not in
> $TOP_OF_DISTRO/lib/Bar/Baz also puzzle me.
This is because ExtUtils::MakeMaker (the traditional install mechanism)
doesn't properly support the lib/Bar/Baz structure, and wants all the xs
files at the top-level.
Ben
--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC ben@morrow.me.uk
------------------------------
Date: Thu, 17 Jun 2004 18:49:54 GMT
From: "Max" <max@NOSPAMkipness.com>
Subject: Why won't this split file script work?
Message-Id: <mJlAc.2227$Pt.1153@newssvr19.news.prodigy.com>
I can't seem to figure out what I'm doing wrong, or maybe I'm just rushing
as I need to split a 15000 line file into chunks.
This script is supposed to work by giving the line number you want to start
at and the line number you want to stop at. It should copy all lines in
between the start and stop number to a file called $file-split. But it
doesn't seem to work. If someone has a few minutes, can you tell me what
I'm doing wrong.
Thanks in advance.
#!/usr/bin/perl
$file = $ARGV[0];
$start = $ARGV[1];
$stop = $ARGV[2];
print "$start\n";
print "$stop\n";
$cnt = 0;
open (IN, "$file");
open (OUT, "> $file-split");
while (<IN>) {
chomp;
$cnt++;
next if ($cnt lt $start);
last if ($cnt gt $stop);
print OUT "$_\n";
}
close (IN);
close (OUT);
------------------------------
Date: 17 Jun 2004 21:04:31 +0200
From: Michal Wojciechowski <odyniec-usenet@odyniec.net>
Subject: Re: Why won't this split file script work?
Message-Id: <87smcu2egw.fsf@odyniec.odyniec.net>
"Max" <max@NOSPAMkipness.com> writes:
[...]
> $cnt++;
> next if ($cnt lt $start);
> last if ($cnt gt $stop);
Here, you are using the stringwise relational operators (lt ang gt),
while you should be using the numerical ones (< and >).
--
Michal Wojciechowski : for(<>){/\s/,$l{$m=$`}=$'}$_ : 10 PRINT "Yet another"
odyniec()odyniec;net : =$l{$c},/O\s/?$c=$'-1:y/"//d : 20 PRINT "Perl hacker"
http://odyniec.net : ,/T\s/?print$':0while$c++<$m : 30 GOTO 10
------------------------------
Date: Thu, 17 Jun 2004 15:10:38 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Max <max@kipness.com>
Subject: Re: Why won't this split file script work?
Message-Id: <Pine.SGI.3.96.1040617150701.326419A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Thu, 17 Jun 2004, Max wrote:
>This script is supposed to work by giving the line number you want to start
>at and the line number you want to stop at. It should copy all lines in
>between the start and stop number to a file called $file-split. But it
>doesn't seem to work. If someone has a few minutes, can you tell me what
>$cnt = 0;
>
>open (IN, "$file");
>open (OUT, "> $file-split");
>
>while (<IN>) {
>
> chomp;
> $cnt++;
You can just use the $. variable instead of $cnt.
> next if ($cnt lt $start);
> last if ($cnt gt $stop);
You're using string-wise operators. You want numerical comparisons:
next if $. < $start;
last if $. > $stop;
> print OUT "$_\n";
Why did you chomp() $_ if you're just going to print it with a newline at
the end again?
>}
>
>close (IN);
>close (OUT);
I'd write this as:
while (<IN>) {
print OUT if ($. == $start) .. ($. == $stop);
last if $. == $stop;
}
That's using the .. operator (perldoc perlop).
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Thu, 17 Jun 2004 20:34:08 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Why won't this split file script work?
Message-Id: <40D2002D.3442F71E@acm.org>
Max wrote:
>
> I can't seem to figure out what I'm doing wrong, or maybe I'm just rushing
> as I need to split a 15000 line file into chunks.
>
> This script is supposed to work by giving the line number you want to start
> at and the line number you want to stop at. It should copy all lines in
> between the start and stop number to a file called $file-split. But it
> doesn't seem to work. If someone has a few minutes, can you tell me what
> I'm doing wrong.
>
> Thanks in advance.
>
> #!/usr/bin/perl
You should enable warnings and strictures to let perl help you find
mistakes.
use warnings;
use strict;
> $file = $ARGV[0];
> $start = $ARGV[1];
> $stop = $ARGV[2];
>
> print "$start\n";
> print "$stop\n";
>
> $cnt = 0;
>
> open (IN, "$file");
> open (OUT, "> $file-split");
You should *ALWAYS* verify that the files were opened correctly.
open IN, $file or die "Cannot open $file: $!";
open OUT, "> $file-split" or die "Cannot open $file-split: $!";
> while (<IN>) {
>
> chomp;
> $cnt++;
> next if ($cnt lt $start);
> last if ($cnt gt $stop);
You are using string comparison operators which are not doing what you
seem to expect them to do.
$ perl -le'
for ( qw[ 1 2 3 4 10 11 12 13 14 20 21 22 23 24 100 200 300 ] ) {
print if $_ lt "12"
}
'
1
10
11
100
Note that '100' is less than '12'. You should be using numerical
comparison operators instead. Also you don't need the $cnt variable as
perl provides the $. variable which does the same thing.
next if $. < $start;
last if $. > $stop;
> print OUT "$_\n";
> }
>
> close (IN);
> close (OUT);
John
--
use Perl;
program
fulfillment
------------------------------
Date: 17 Jun 2004 16:21:29 -0700
From: tchurch@gmail.com (Thomas Church)
Subject: Re: Why won't this split file script work?
Message-Id: <ea0cdb4c.0406171521.388e24e2@posting.google.com>
"Max" <max@NOSPAMkipness.com> wrote in message
news:<mJlAc.2227$Pt.1153@newssvr19.news.prodigy.com>...
> If someone has a few minutes, can you tell me what I'm doing wrong.
From what I can tell, you've made one or two logic errors (you're not telling
the program to do what you want), and then a few stylistic "errors". The
problem, I must assume, is that you use 'lt' and 'gt', rather than '<'
and '>'. The former are for string comparison, the latter for numeric
comparison. That is:
'10' lt '5'
10 > 5
I assume you wanted the numeric comparison. Also, if you input 5 and 8 for
$start and $stop, just lines 6, 7, and 8 are copied. You may want to futz
with the boundaries.
I also made some stylistic changes to the code. The most important is adding
'use strict;' and 'use warnings;', which are the most helpful things in Perl
since spliced bread. The others are less critical, but in the absence of any
preformed habits otherwise, there's no reason not to just use the
three-argument form of open all the time (for example).
One other thought -- if you don't want to keep track of it youself, the
variable $. (dollar-period) contains the current line number of the last
filehandle that you've read from. As long as you're not messing with $/
(which redefines for perl what a line is), $. should always correspond
to your $cnt.
Hope this helps. Code is tested but (of course) not guaranteed.
#!/usr/bin/perl
use strict;
use warnings;
my ($file, $start, $stop) = @ARGV;
print "$start\n$stop\n";
my $cnt = 0;
open (IN, '<', $file) or die "Unable to open $file: $!";
open (OUT, '>', $file . '-split') or die "Unable to open $file-split: $!";
while (<IN>) {
chomp;
$cnt++;
next if ($cnt < $start);
last if ($cnt > $stop);
print OUT "$_\n";
}
close (IN);
close (OUT);
------------------------------
Date: 17 Jun 2004 16:26:20 -0700
From: tchurch@gmail.com (Thomas Church)
Subject: Re: Why won't this split file script work?
Message-Id: <ea0cdb4c.0406171526.77acf2e6@posting.google.com>
"Max" <max@NOSPAMkipness.com> wrote in message
news:<mJlAc.2227$Pt.1153@newssvr19.news.prodigy.com>...
> I can't seem to figure out what I'm doing wrong, or maybe I'm just rushing
> as I need to split a 15000 line file into chunks.
One other thought: you don't need to chomp unless you actually care about
eliminating the newline. Since you add it back in again anyway when you print,
you can simplify the loop to: (untested)
while (<IN>) {
next if ($. < $start);
last if ($. > $stop);
print OUT $_;
}
------------------------------
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 6702
***************************************