[28500] in Perl-Users-Digest
Perl-Users Digest, Issue: 9864 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 18 18:06:03 2006
Date: Wed, 18 Oct 2006 15:05:11 -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 Wed, 18 Oct 2006 Volume: 10 Number: 9864
Today's topics:
Re: Archive::Zip - writeToFileNamed log? <benmorrow@tiscali.co.uk>
Efficient Searching <hlarons@yahoo.com>
Re: Efficient Searching <mritty@gmail.com>
Re: Efficient Searching xhoster@gmail.com
Re: Efficient Searching jgraber@ti.com
Re: Efficient Searching <wahab@chemie.uni-halle.de>
Re: Efficient Searching <rvtol+news@isolution.nl>
Re: END{} block capabilities ? <ynl@nsparks.net>
Re: How to print "0A" LF or "03" ETX characters to a fi <joe@inwap.com>
Re: I have no problems eating cereal...after it softens samiam@mytrashmail.com
Inline replacement issues <dsphunxion@gmail.com>
Re: Inline replacement issues <jgibson@mail.arc.nasa.gov>
Re: LWP and Unicode <benmorrow@tiscali.co.uk>
Re: LWP and Unicode <tzz@lifelogs.com>
Re: LWP and Unicode <rvtol+news@isolution.nl>
Re: modify posting guidelines to allow MIME charset=utf (Randal L. Schwartz)
Re: modify posting guidelines to allow MIME charset=utf <rvtol+news@isolution.nl>
Re: Perl and Dos Batch File Create <bradbrockman@yahoo.com>
Re: Perl and Dos Batch File Create <veatchla@yahoo.com>
Re: Perl and Dos Batch File Create <bradbrockman@yahoo.com>
Re: Perl and Dos Batch File Create <veatchla@yahoo.com>
Re: sending ctrl+C to pipe process <benmorrow@tiscali.co.uk>
Re: system command - redirect also the STDERR to a file <benmorrow@tiscali.co.uk>
unable to calculate large file size himagauri@gmail.com
unable to calculate large file size himagauri@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Oct 2006 15:51:27 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Archive::Zip - writeToFileNamed log?
Message-Id: <fkrh04-dck.ln1@osiris.mauzo.dyndns.org>
Quoth "MoshiachNow" <lev.weissman@creo.com>:
>
> How do I get it to log? the whole operation is long and silent...Only
> the exit code is available...
> $zip->writeToFileNamed($ZIPNAME);
>
> It's a long operation on big files,but I do not seem to manage to get
> it's log...
I would use $zip->writeToFileHandle with a tied filehandle. Then you can
display whatever progress reports you like.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
benmorrow@tiscali.co.uk The Levellers, 'Believers'
------------------------------
Date: Wed, 18 Oct 2006 18:40:11 -0000
From: HaroldWho <hlarons@yahoo.com>
Subject: Efficient Searching
Message-Id: <slrnejct8b.jr.hlarons@Beagle.mylocal.net>
I have an 2.7 Mb, 75,000 line comma-separated ASCII file with each line
of the form: integer_1,integer_2,string_1,string_2
Given a target integer, I need to search for the record for which
target >= integer_1 && target <= integer_2.
I have tried this in two ways. First, by creating an array from the
whole file in which each array element is a pointer to an array of each
of the 4 items on a line in the file.
Alternatively, I create a hash with integer_1 as key and as the value,
a pointer to an array of the other 3 values on the line: integer_2,
string_1, string_2.
Searching using the hash approach is significantly slower than using
the array approach. Thus for 200 target values, the array search takes
10 - 12 sec, whereas the hash search takes 35 - 40 sec.
1. Does it seem reasonable that the hash search is so much slower?
2. Am I missing a completely different approach to the search?
HW
--
Powered by Slackware 10.2 Linux -- Kernel 2.6.13
News Reader slrn 0.9.8.1
------------------------------
Date: 18 Oct 2006 11:45:26 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Efficient Searching
Message-Id: <1161197126.334738.91680@b28g2000cwb.googlegroups.com>
HaroldWho wrote:
> I have an 2.7 Mb, 75,000 line comma-separated ASCII file with each line
> of the form: integer_1,integer_2,string_1,string_2
>
> Given a target integer, I need to search for the record for which
> target >= integer_1 && target <= integer_2.
>
> I have tried this in two ways. First, by creating an array from the
> whole file in which each array element is a pointer to an array of each
> of the 4 items on a line in the file.
Why? Your description says nothing about needing the last two values.
> Alternatively, I create a hash with integer_1 as key and as the value,
> a pointer to an array of the other 3 values on the line: integer_2,
> string_1, string_2.
Why? Your description says nothing about needing the last two values.
> Searching using the hash approach is significantly slower than using
> the array approach. Thus for 200 target values, the array search takes
> 10 - 12 sec, whereas the hash search takes 35 - 40 sec.
>
> 1. Does it seem reasonable that the hash search is so much slower?
You haven't shown *any* code that shows how you're using the hash, so
it's not possible to give a definate answer. However, yes, it seems
reasonable to me. Hashes are used to get a very specific piece of
associated data. That is, if foo is associated with bar, it's
lightning quick to find bar if I know foo. You do not know "foo". All
you know is that you want "foo" to be less than what you have, and
"foo"'s value to be greater than what you have. This is not what
hashes are for.
> 2. Am I missing a completely different approach to the search?
Did you try sorting your array in approach #1 before beginning a linear
search? I honestly have no idea if it'd be any faster, but there's no
reason not to try.
Did you try not putting the entire file into the array, and just
reading the file line-by-line, stopping when you find the right line?
I don't know if it would cause any speed improvements, but it would
certainly improve the memory usage.
Paul Lalli
------------------------------
Date: 18 Oct 2006 19:34:35 GMT
From: xhoster@gmail.com
Subject: Re: Efficient Searching
Message-Id: <20061018153541.707$RO@newsreader.com>
HaroldWho <hlarons@yahoo.com> wrote:
> I have an 2.7 Mb, 75,000 line comma-separated ASCII file with each line
> of the form: integer_1,integer_2,string_1,string_2
>
> Given a target integer, I need to search for the record for which
> target >= integer_1 && target <= integer_2.
By saying "*the* record", do you mean that there can be only one such
record, which means the record-ranges cannot overlap? If so, then a simple
binary search will give you the solution quickly. Otherwise, it is more
complicated. You could use kd trees or R trees or quad trees or just some
static binning method.
> I have tried this in two ways. First, by creating an array from the
> whole file in which each array element is a pointer to an array of each
> of the 4 items on a line in the file.
>
> Alternatively, I create a hash with integer_1 as key
What if two lines both have the same integer_1?
> and as the value,
> a pointer to an array of the other 3 values on the line: integer_2,
> string_1, string_2.
You have described two ways of storing the data. You have not described
any way you search upon that stored data. Are you simply iterating over
all of the data and testing the boundaries explicitly?
my $found = scalar grep {$_->[0]<$target and $_->[1]>$target} @x;
> Searching using the hash approach is significantly slower than using
> the array approach. Thus for 200 target values, the array search takes
> 10 - 12 sec, whereas the hash search takes 35 - 40 sec.
>
> 1. Does it seem reasonable that the hash search is so much slower?
Yeah.
> 2. Am I missing a completely different approach to the search?
Mostly what you are missing is a better description of the problem (Can the
intervals overlap? How wide is a typical interval compared to the entire
range covered by all intervals?) and some actual code to show us what you
are doing.
Maybe check out Tie::RangeHash.
Range searching queries seem to be all the rage lately.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 18 Oct 2006 14:33:30 -0500
From: jgraber@ti.com
Subject: Re: Efficient Searching
Message-Id: <yvnbqo95shh.fsf@famous02.dal.design.ti.com>
HaroldWho <hlarons@yahoo.com> writes:
> I have an 2.7 Mb, 75,000 line comma-separated ASCII file with each line
> of the form: integer_1,integer_2,string_1,string_2
>
> Given a target integer, I need to search for the record for which
> target >= integer_1 && target <= integer_2.
>
> I have tried this in two ways. First, by creating an array from the
> whole file in which each array element is a pointer to an array of each
> of the 4 items on a line in the file.
>
> Alternatively, I create a hash with integer_1 as key and as the value,
> a pointer to an array of the other 3 values on the line: integer_2,
> string_1, string_2.
>
> Searching using the hash approach is significantly slower than using
> the array approach. Thus for 200 target values, the array search takes
> 10 - 12 sec, whereas the hash search takes 35 - 40 sec.
>
> 1. Does it seem reasonable that the hash search is so much slower?
Yes
> 2. Am I missing a completely different approach to the search?
Definitely, since there are dozens or hundreds of search methods,
and you have only vaguely listed two.
If you create a sample program and sample data that people here
can cut and paste to run, you will likely get better suggestions.
Your script should create a sample dataset, rather than provide 2.7MB.
Without that there is no way to know what you are doing suboptimally
or what your data looks like.
With only 2.7Mbits of data, I calculate you
have less than 4 characters per line average.
If you mean 2.7e6 Bytes of data, that is 36 characters per line average,
even so it is easy to keep the whole thing in memory, even on a cell phone.
Are the records equal length?
Are the integers consecutive, or very sparce? ie what is range of integers?
Do you intend to do many lookups on the same dataset in one session?
Is integer2 always > than integer1?
Is the file already sorted by integer1?
Are there targets that do not have a match in the file?
If there are no possible targets that do not have a match,
then you dont really need both integers.
If the integers have a range of less than 1e6 or so,
you could just create an array lookup table for every possible target.
If you provide enough data, and the data format is just right,
perhaps Abigail can come up with a regular expression as a search method.
Otherwise, slurp to an array, sort the array(if not already sorted),
then do a binary search, which should be able to find each record
in 17 comparisons. Although I read somewhere that 70% of CS students
cannot program a binary search correctly, pehaps there is a CPAN
module for binary searching already written by one of the other 30%.
--
Joel
------------------------------
Date: Wed, 18 Oct 2006 22:15:55 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: Efficient Searching
Message-Id: <eh62av$8b4$1@mlucom4.urz.uni-halle.de>
Thus spoke HaroldWho (on 2006-10-18 20:40):
> I have an 2.7 Mb, 75,000 line comma-separated ASCII file with each line
> of the form: integer_1,integer_2,string_1,string_2
> Given a target integer, I need to search for the record for which
> target >= integer_1 && target <= integer_2.
As some others here have shown too, I cant't keep
myself from guessing what your problem is ;-)
I'd think you have a .csv which has a very
regular structure (otherwise, the regex below
needs some modification), roughly like:
...
1499,1883,my99996,your99996
1524,1938,my99995,your99995
1811,1886,my99994,your99994
1387,1945,my99993,your99993
...
If that is so and its that small
as you wrote above (only 75K lines),
then a simple regex on the slurped file
will pull the results in under 1/2 sec on
a today's standard machine, eg.:
use strict;
use warnings;
use re 'eval';
my $targ = shift or die "no target\n";
open(my $inh, '<', 'stuff.csv') or die "for a reason $!";
my $content = do {local $/; <$inh>};
close $inh;
my @ar = ();
my $rg = qr/([^,\n]+)[,\n]+
([^,\n]+)[,\n]+
([^,\n]+)[,\n]+
([^,\n]+)[,\n]+
(?{push @ar, [$1,$2,$3,$4] if( $targ>=$1 && $targ<=$2 )})
/mx;
1 while $content =~ /$rg/g; # pull results
print "hits found = ", scalar @ar, "\n";
print "$_->[0] $_->[1] $_->[2] $_->[3]\n" for @ar;
Regards
Mirco
------------------------------
Date: Wed, 18 Oct 2006 22:55:36 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Efficient Searching
Message-Id: <eh6bl7.13o.1@news.isolution.nl>
Mirco Wahab schreef:
> my $content = do {local $/; <$inh>};
For files with unknown size limits, change to
my $content ; {local $/ ; $content = <$inh>}
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 19 Oct 2006 00:03:39 +0200
From: Yohan N Leder <ynl@nsparks.net>
Subject: Re: END{} block capabilities ?
Message-Id: <MPG.1fa0c32816059f409898e9@news.tiscali.fr>
In article <4pmfudFjcgf6U1@news.dfncis.de>, anno4000@radom.zrz.tu-
berlin.de says...
> > our ($rc, $4sub1, $4sub2, $4sub3);
> ^^^^^^^^^^^^^^^^^^^^^^
> These aren't legal variable names.
Because of number a beginning : well, so $_4sub1, it was just an
untested example.
>
> How are $4sub1 etc. supposed to get values?
>
Simply from sub which change value of global variables.
For example :
#!/usr/bin/perl
use strict;
use warnings;
$|=1;
print "Content-type: text/html\n\n";
our $_sub1 = 1;
print "<p>\$_sub1 before sub1() : ".$_sub1."<br>";
my $rc = &sub1;
print "\$_sub1 after sub1() : ".$_sub1."<br>";
print "while sub1() returned : ".$rc."</p>";
exit 0;
sub sub1{
$_sub1 += 1;
return 4;}
> You can use tighter-scoped lexicals to control the behavior of END.
> Declare them inside the END block and define an accessor (untested):
>
> END {
> my %end_control;
> sub end_control {
> my ( $key, $value) = @_;
> $end_control{ $key} = $value;
> }
>
> if ( $end_control{ sub1} eq 'foo' ) {
> # ...
> }
> # etc.
> }
>
> In the main part, call control_end( 'sub1', 'foo') to activate an
> action in END.
>
Hum, I see the general principle : the stuff is to embbed a
'decisional' hash inside END block (rather than my global scalars) and
manage it from the rest of the code through a sub which is also inside
this same END block. OK ! Thanks Anno.
------------------------------
Date: Wed, 18 Oct 2006 13:15:24 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: How to print "0A" LF or "03" ETX characters to a filehandle
Message-Id: <b9Cdnd4LvrAAFqvYnZ2dnUVZ_sOdnZ2d@comcast.com>
jeffpierce12@hotmail.com wrote:
> open (ABC, "+< /dev/ttyS0") or die "Can't open serial port: $!";
> binmode ABC;
> print (ABC "2");
> ......
Are you aware that
print ABC chr(0x03),chr(0x0A);
and
print ABC "\x03\x0A";
both do the same thing?
-Joe
------------------------------
Date: 18 Oct 2006 11:30:30 -0700
From: samiam@mytrashmail.com
Subject: Re: I have no problems eating cereal...after it softens. Why is replacing a simple string so hard then?
Message-Id: <1161196230.570883.105770@h48g2000cwc.googlegroups.com>
Just wanted to say that I received some very nice offline emails and
wanted to say thank you in particular to Brian Wilkins. Thanks for your
code and your gracious nature Brian.
Also to Mr. Ritty aka Paul Lalli - sorry my dissension rankled you so.
I am still grateful for your input.
Thanks to all who contribute, but especially to those whose gifts are
vitriol free :-)
L,
S
------------------------------
Date: 18 Oct 2006 12:53:15 -0700
From: "sil" <dsphunxion@gmail.com>
Subject: Inline replacement issues
Message-Id: <1161201195.225741.136280@k70g2000cwa.googlegroups.com>
Hey all. I have 4500+ files all close to being the same. I'm trying to
do an inplace edit for one variable but I can't seem to finesse it...
I have the following line inside every file
238 SOMETHING email:somewhere@someplace.com MAIL/4.2\r
The number 238 is always changing and I need to remove those numbers
altogether to leave:
SOMETHING email:somewhere@someplace.com MAIL/4.2\r
Most of the changes I've made using awk, sed and perl (perl -pi -e
's/something/something else/g') but I can't find a way around this
one... Remember the numbers change so in on instance it may be:
238 SOMETHING email:somewhere@someplace.com MAIL4.2\r
The next it may be:
1444 SOMETHING email:somewhere@someplace.com MAIL4.2\r
Any thoughts in this?
------------------------------
Date: Wed, 18 Oct 2006 14:17:01 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Inline replacement issues
Message-Id: <181020061417012571%jgibson@mail.arc.nasa.gov>
In article <1161201195.225741.136280@k70g2000cwa.googlegroups.com>, sil
<dsphunxion@gmail.com> wrote:
> Hey all. I have 4500+ files all close to being the same. I'm trying to
> do an inplace edit for one variable but I can't seem to finesse it...
>
> I have the following line inside every file
>
> 238 SOMETHING email:somewhere@someplace.com MAIL/4.2\r
>
> The number 238 is always changing and I need to remove those numbers
> altogether to leave:
>
> SOMETHING email:somewhere@someplace.com MAIL/4.2\r
>
> Most of the changes I've made using awk, sed and perl (perl -pi -e
> 's/something/something else/g') but I can't find a way around this
> one... Remember the numbers change so in on instance it may be:
>
> 238 SOMETHING email:somewhere@someplace.com MAIL4.2\r
>
> The next it may be:
>
> 1444 SOMETHING email:somewhere@someplace.com MAIL4.2\r
>
> Any thoughts in this?
>
Use a regular expression:
s{ \A \d+ \s* }{}x;
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Wed, 18 Oct 2006 16:51:59 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: LWP and Unicode
Message-Id: <v5vh04-dck.ln1@osiris.mauzo.dyndns.org>
Quoth Ted Zlatanov <tzz@lifelogs.com>:
> So is there a consensus that MIME with charset=utf8 and a suitable
> 8-bit-safe content-transfer-encoding should be acceptable in
> comp.lang.perl.misc? It's unlikely to do violent things to anyone's
> news reader, and it would make it much easier to post Perl code that
> uses UCS characters in source.
For my part, if I get a vote :), I'd say UTF8 with no CTE, since Usenet
is in practice 8-bit safe, Base64 is terribly wasteful and QP is
horribly messy to read if you don't grok MIME.
Ben
--
Although few may originate a policy, we are all able to judge it.
Pericles of Athens, c.430 B.C.
benmorrow@tiscali.co.uk
------------------------------
Date: Wed, 18 Oct 2006 20:29:44 +0100
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: LWP and Unicode
Message-Id: <g69u021bexj.fsf@lifelogs.com>
On 18 Oct 2006, benmorrow@tiscali.co.uk wrote:
> Quoth Ted Zlatanov <tzz@lifelogs.com>:
>> So is there a consensus that MIME with charset=utf8 and a suitable
>> 8-bit-safe content-transfer-encoding should be acceptable in
>> comp.lang.perl.misc? It's unlikely to do violent things to anyone's
>> news reader, and it would make it much easier to post Perl code that
>> uses UCS characters in source.
>
> For my part, if I get a vote :), I'd say UTF8 with no CTE, since Usenet
> is in practice 8-bit safe, Base64 is terribly wasteful and QP is
> horribly messy to read if you don't grok MIME.
Agreed on the above in theory, but in practice it's much easier to get
a consensus with my parameters than yours.
Ted
------------------------------
Date: Wed, 18 Oct 2006 21:27:56 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: LWP and Unicode
Message-Id: <eh66ad.13o.1@news.isolution.nl>
Ben Morrow schreef:
> I'd say UTF8 with no CTE
ITYM: UTF8, with a default CTE of 8-bit if absent.
But some news clients might assume 7-bit, if the CTE is absent.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 18 Oct 2006 12:50:54 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: modify posting guidelines to allow MIME charset=utf8
Message-Id: <86ac3tbdy9.fsf@blue.stonehenge.com>
>>>>> "Ted" == Ted Zlatanov <tzz@lifelogs.com> writes:
Ted> What do the news admins have to do?
Agree.
Ted> Usenet is not a prison. comp.lang.perl.misc is not even moderated.
Ted> Can you explain your analogy a little bit?
The analogy is that *this* is not *yours* and not *mine*. *This* belongs
to the people who run Usenet. Unless you're also in charge of a spool
somewhere, you are *not* an admin and have *no* say about the format
of the messages or even the charter. Even if you *are* in charge of
a spool, you don't get interchange rights unless you play along well
with the *collective* *anarchy* known as "Usenet".
So, that's how it applies. You can vote all you want, but it's ultimately up
to the people running the show, and that's NOT US in THIS GROUP. It's the
people in news.admin. As far as I remember last time I looked, MIME is *not*
acceptable, here or anywhere on Usenet except in groups that match
"*.binaries.*".
Just another Usenet old-timer (since 1980 when it first began),
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
Posted via a free Usenet account from http://www.teranews.com
------------------------------
Date: Wed, 18 Oct 2006 23:20:50 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: modify posting guidelines to allow MIME charset=utf8
Message-Id: <eh6d46.1i8.1@news.isolution.nl>
Randal L. Schwartz schreef:
> You can vote all you want, but it's
> ultimately up to the people running the show, and that's NOT US in
> THIS GROUP. It's the people in news.admin. As far as I remember
> last time I looked, MIME is *not* acceptable, here or anywhere on
> Usenet except in groups that match "*.binaries.*".
MIME is being used in text groups on Usenet a lot for ages now and
AFAICS it doesn't cause real problems. I have never noticed propagation
problems for such articles.
Without many complaints, it is safe to assume that using MIME (and
UTF-8) in this group is feasible.
The voting I parsed as little more than a channel for any complaints on
using (or even the promotion of using) MIME (and UTF-8) in clpm. So I
assume it is OK to promote it for textual data that contains non-ASCII
characters.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: 18 Oct 2006 11:12:16 -0700
From: "banker123" <bradbrockman@yahoo.com>
Subject: Re: Perl and Dos Batch File Create
Message-Id: <1161195133.976166.291780@b28g2000cwb.googlegroups.com>
This code prints each line to test.bat, however it does not create a
seperate bat file using the variable.
banker123 wrote:
> open (data, 'source data') or die ("Cannot Open");
> open (test, ">test.bat") or die ("Cannot Open");
> @array=<data>;
> foreach $line (@array)
> {
> chop($line);
> ($rec1,$rec2,)=split(/\t/,$line);
> print test "\\CPC06LBA03S\APPS\FORMWARE\PROGRAMS\JFCLIENT.EXE /f=$rec2
> /n=001";
> }
>
>
>
> David Peacock wrote:
> > banker123 <bradbrockman@yahoo.com> wrote:
> > > I am new to Perl and I am trying to use Perl to complete this task.
> >
> > Welcome.
> >
> > > I have a source file that list the parameter that needs to be inserted
> > > into a batch file, as shown below the parameter needs to be inserted
> > > after JFCLIENT.EXE/f=********* followed by /n=001 the parameter is the
> > <snip>
> >
> > Thanks for the spec, it may be useful information to keep in mind when
> > we analyse your code.
> >
> > Please post what you have tried so far and indicate which parts you
> > would like help with.
> >
> > > Since I'm fairly new this is my first real task using Perl, I
> > > appreciate help getting started.
> > <snip>
> >
> > http://learn.perl.org/ will help you get started out.
> >
> > --
> > David Peacock - davidjpeacock@magma.ca
> > http://quasicanuck.blogspot.com/
------------------------------
Date: Wed, 18 Oct 2006 13:20:23 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: Perl and Dos Batch File Create
Message-Id: <12jcs33lug5no0f@news.supernews.com>
banker123 wrote:
top posting corrected.
>
> David Peacock wrote:
>> banker123 <bradbrockman@yahoo.com> wrote:
>>> I am new to Perl and I am trying to use Perl to complete this task.
>> Welcome.
>>
>>> I have a source file that list the parameter that needs to be inserted
>>> into a batch file, as shown below the parameter needs to be inserted
>>> after JFCLIENT.EXE/f=********* followed by /n=001 the parameter is the
>> <snip>
>>
[snip]
>
> open (data, 'source data') or die ("Cannot Open");
Is 'source data' your real file name? Tell die to give you more
information about why the open failed.
.... or die "Cannot open source data, $!";
> open (test, ">test.bat") or die ("Cannot Open");
Improve your die as in above.
You initially stated that you need a batch file for each line in you
input. This will create 1 batch file with each command. Which do you
require? If 1 batch file per input line, then move the open() and
close() of $rec1 inside your loop below.
> @array=<data>;
Do not read the entire input file into memory unless the file is small.
> foreach $line (@array)
Better to read directly from the input filehandle
while (my $line = <data>) {
> {
> chop($line);
use chomp() to remove newline from the end of the line. chop() removes
the last character.
> ($rec1,$rec2,)=split(/\t/,$line);
> print test "\\CPC06LBA03S\APPS\FORMWARE\PROGRAMS\JFCLIENT.EXE /f=$rec2
> /n=001";
> }
>
>
--
Len
------------------------------
Date: 18 Oct 2006 11:33:23 -0700
From: "banker123" <bradbrockman@yahoo.com>
Subject: Re: Perl and Dos Batch File Create
Message-Id: <1161196399.650596.79440@e3g2000cwe.googlegroups.com>
You initially stated that you need a batch file for each line in you
input. This will create 1 batch file with each command. Which do you
require? If 1 batch file per input line, then move the open() and
close() of $rec1 inside your loop below.
I need 1batch file with each command.
I also need that bathh file named using the $rec1.bat.
Can you provide some more info on how and where to add the open in the
loop?
I am getting 1 batch file with each line and the bacth file is named
$rec1.bat not what I want.
Thanks!
l v wrote:
> banker123 wrote:
>
> top posting corrected.
>
> >
> > David Peacock wrote:
> >> banker123 <bradbrockman@yahoo.com> wrote:
> >>> I am new to Perl and I am trying to use Perl to complete this task.
> >> Welcome.
> >>
> >>> I have a source file that list the parameter that needs to be inserted
> >>> into a batch file, as shown below the parameter needs to be inserted
> >>> after JFCLIENT.EXE/f=********* followed by /n=001 the parameter is the
> >> <snip>
> >>
> [snip]
> >
>
> > open (data, 'source data') or die ("Cannot Open");
>
> Is 'source data' your real file name? Tell die to give you more
> information about why the open failed.
> .... or die "Cannot open source data, $!";
>
>
> > open (test, ">test.bat") or die ("Cannot Open");
>
> Improve your die as in above.
> You initially stated that you need a batch file for each line in you
> input. This will create 1 batch file with each command. Which do you
> require? If 1 batch file per input line, then move the open() and
> close() of $rec1 inside your loop below.
>
> > @array=<data>;
>
> Do not read the entire input file into memory unless the file is small.
>
> > foreach $line (@array)
> Better to read directly from the input filehandle
> while (my $line = <data>) {
>
> > {
> > chop($line);
> use chomp() to remove newline from the end of the line. chop() removes
> the last character.
>
>
> > ($rec1,$rec2,)=split(/\t/,$line);
> > print test "\\CPC06LBA03S\APPS\FORMWARE\PROGRAMS\JFCLIENT.EXE /f=$rec2
> > /n=001";
> > }
> >
> >
>
> --
>
> Len
------------------------------
Date: Wed, 18 Oct 2006 14:52:49 -0500
From: l v <veatchla@yahoo.com>
Subject: Re: Perl and Dos Batch File Create
Message-Id: <12jd1gdahk9rk0e@news.supernews.com>
banker123 wrote:
top posting corrected again.
> l v wrote:
>> banker123 wrote:
>>
>> top posting corrected.
>>
>>> David Peacock wrote:
>>>> banker123 <bradbrockman@yahoo.com> wrote:
>>>>> I am new to Perl and I am trying to use Perl to complete this task.
>>>> Welcome.
>>>>
>>>>> I have a source file that list the parameter that needs to be inserted
>>>>> into a batch file, as shown below the parameter needs to be inserted
>>>>> after JFCLIENT.EXE/f=********* followed by /n=001 the parameter is the
>>>> <snip>
>>>>
>> [snip]
>> > open (data, 'source data') or die ("Cannot Open");
>>
>> Is 'source data' your real file name? Tell die to give you more
>> information about why the open failed.
>> .... or die "Cannot open source data, $!";
>>
>>
>> > open (test, ">test.bat") or die ("Cannot Open");
>>
>> Improve your die as in above.
>> You initially stated that you need a batch file for each line in you
>> input. This will create 1 batch file with each command. Which do you
>> require? If 1 batch file per input line, then move the open() and
>> close() of $rec1 inside your loop below.
>>
>> > @array=<data>;
>>
>> Do not read the entire input file into memory unless the file is small.
>>
>> > foreach $line (@array)
>> Better to read directly from the input filehandle
>> while (my $line = <data>) {
>>
>> > {
>> > chop($line);
>> use chomp() to remove newline from the end of the line. chop() removes
>> the last character.
>>
>>
>> > ($rec1,$rec2,)=split(/\t/,$line);
>> > print test "\\CPC06LBA03S\APPS\FORMWARE\PROGRAMS\JFCLIENT.EXE /f=$rec2
>> > /n=001";
>> > }
>> >
>> >
>>
>> --
>>
>> Len
>
> You initially stated that you need a batch file for each line in you
> input. This will create 1 batch file with each command. Which do you
> require? If 1 batch file per input line, then move the open() and
> close() of $rec1 inside your loop below.
>
> I need 1batch file with each command.
> I also need that bathh file named using the $rec1.bat.
> Can you provide some more info on how and where to add the open in the
> loop?
> I am getting 1 batch file with each line and the bacth file is named
> $rec1.bat not what I want.
> Thanks!
>
>
>
You would open and close your output file using the $rec1 as your
filename within the iterations for each line in your input file. Print
would be between the open and close. This is a common programming
concept regardless of the programming language. Being new to Perl
should not make you forget program logic.
Remember to post your updated code for further assistance and please
don't top post in this NG.
--
Len
------------------------------
Date: Wed, 18 Oct 2006 15:18:29 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: sending ctrl+C to pipe process
Message-Id: <lmph04-dck.ln1@osiris.mauzo.dyndns.org>
Quoth Joe Smith <joe@inwap.com>:
> linbox wrote:
> > if ($pid) { # parent
> > print "parents pid = $pid \n";
> > sleep (5);
> > $result=kill (9,$pid);
>
> if ($pid) { # running as the parent
> print "Child's pid = $pid (my pid = $$)\n";
> sleep 5;
> $result = kill(2,$pid) || kill(3,$pid); #SIGINT, SIGQUIT
1. ^^ ^^ 2. ^^^^^^^^^^^^^^^
1. Use signal numbers out of POSIX.pm, or use named signals, mostly
because of the self-documentation: I'm not aware of any system where
(SIGINT, SIGQUIT) != (2, 3), but if there is you won't get bitten.
2. Why send those signals? SIGINT means 'keyboard interrupt' and SIGQUIT
means 'the user asked for a core dump'; lying isn't polite. The signal
to ask a process to terminate is SIGTERM. Also, SIGQUIT dumps core,
which is certainly not something you want to be doing.
> sleep 1;
> kill(0,$pid) and kill(9,$pid); # SIGKILL if not yet gone
The kill 0 is useless, particularly as there is a race condition between
that and the kill 9. If you're worried about pid wraparound (or
randomised pids picking the same one again) then you need to use waitpid
with WNOHANG.
> > The variable $pid is still different than the pid of sox.
>
> Probably because 'rec' is not 'sox'. If 'rec' is a shell script,
> then: 1) 'sox' will have a different pid, and 2) sending a nice
> signal (not SIGKILL) to 'rec' should be sufficient to get 'rec'
> to forward that same signal to 'sox'.
Also, if you do get to the point of killing a shell script with SIGKILL,
it's probably worth killing the whole process group. You may need to put
the child in it's own pgrp yourself (which means forking and so on by
hand, rather that using magic open): I must admit I don't know if a
shell does that by default, or if perl's magic open does it.
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 benmorrow@tiscali.co.uk
------------------------------
Date: Wed, 18 Oct 2006 16:49:18 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: system command - redirect also the STDERR to a file
Message-Id: <u0vh04-dck.ln1@osiris.mauzo.dyndns.org>
Quoth "MoshiachNow" <lev.weissman@creo.com>:
>
> Running an AciveState on W2K,I dod not manage to redirect also the
> STDERR to a file.STDOUT is in the file "COPY",STDERR is not.
>
> system("xcopy /f /y $_ >COPY 2>&1") ;
Running Win2k,
C:\> perl -e"system 'xcopy /f /y foo bar >COPY 2>&1'"
(line split for Usenet) worksforme.
What is in $_ at that point? If I attempt to xcopy a file to a path that
doesn't exist, xcopy appears to hang as it is asking if bar is a file or
directory, but you can't see the question as it's gone in the log.
What are your environment variables COMSPEC and PERL5SHELL set to?
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
benmorrow@tiscali.co.uk (Kate Rusby)
------------------------------
Date: 18 Oct 2006 14:37:02 -0700
From: himagauri@gmail.com
Subject: unable to calculate large file size
Message-Id: <1161207422.059666.73140@m73g2000cwd.googlegroups.com>
Hi
My perl script is a very big script and performs a lot of complex
tasks. One of the tasks within the script is to calulate the size of a
file as follows:
$size = -s $filename;
$size = -1 unless defined($size);
When the file size is larger than 1GB for example 16376862124 bytes or
16 GB, the script returns $size = -1
For a file size less than 1 GB for example 775752944 bytes,
the correct file size is returned.
When I run another sample script performing just the above simple task
of calculating file size, the correct size of 16376862124 bytes is
returned for the larger file after a long time-about 40 minutes. The
problem arises when the above task is within the larger script.
I'm using Perl Version 5.8.3
If I do a perl -V, I do get the following option in the summary:
uselargefiles=define
So where could the problem lie?
Please suggest a solution to my problem.
-Thanks,
Regards,
Gauri
------------------------------
Date: 18 Oct 2006 14:37:16 -0700
From: himagauri@gmail.com
Subject: unable to calculate large file size
Message-Id: <1161207435.999589.191300@h48g2000cwc.googlegroups.com>
Hi
My perl script is a very big script and performs a lot of complex
tasks. One of the tasks within the script is to calulate the size of a
file as follows:
$size = -s $filename;
$size = -1 unless defined($size);
When the file size is larger than 1GB for example 16376862124 bytes or
16 GB, the script returns $size = -1
For a file size less than 1 GB for example 775752944 bytes,
the correct file size is returned.
When I run another sample script performing just the above simple task
of calculating file size, the correct size of 16376862124 bytes is
returned for the larger file after a long time-about 40 minutes. The
problem arises when the above task is within the larger script.
I'm using Perl Version 5.8.3
If I do a perl -V, I do get the following option in the summary:
uselargefiles=define
So where could the problem lie?
Please suggest a solution to my problem.
-Thanks,
Regards,
Gauri
------------------------------
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 9864
***************************************