[22138] in Perl-Users-Digest
Perl-Users Digest, Issue: 4359 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 7 18:06:05 2003
Date: Tue, 7 Jan 2003 15:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 7 Jan 2003 Volume: 10 Number: 4359
Today's topics:
Re: A Good Perl Book (Sara)
Re: A Good Perl Book (Charles Blair)
autoresponse email (web tur)
Re: autoresponse email <nobody@dev.null>
Re: autoresponse email <me@privacy.net>
Re: autoresponse email (web tur)
Re: error with @ sign <mouseslinger@hotmail.com>
Re: error with @ sign (Tad McClellan)
Re: error with @ sign (Sara)
file size limits of perl Net::ftp <olli2@biop.uni-hannover.de>
Find fixed drives in BATCH file or a PERL script (Mehul)
Re: Find fixed drives in BATCH file or a PERL script <s.patterson@freeuk.com>
Re: Find fixed drives in BATCH file or a PERL script (Malcolm Dew-Jones)
Re: finding largest repeat values in array ctcgag@hotmail.com
Re: finding largest repreat value in an array <mbudash@sonic.net>
Re: insert newlines in a long string <truthxayer@yahoo.com>
Need help grabbing text from multiple lines <jfkingsley@earthlink.net>
Re: Need help grabbing text from multiple lines <mthunter@students.uiuc.edu>
Re: Need help grabbing text from multiple lines <mbudash@sonic.net>
Nested sort (Lee)
nested try blocks causing problems (Matt Venn)
Nicer way to pass argument to program <stremitz@consultant.com>
Re: Nicer way to pass argument to program <shondell@cis.ohio-state.edu>
Re: Nicer way to pass argument to program (h\)
Re: Nicer way to pass argument to program (Tad McClellan)
Re: Perl quotations problem <kasp@epatra.com>
Re: Problem with huge dataset, 100000000 a magic number (M.J.T. Guy)
Re: reading output of tar in blocks <me@privacy.net>
Re: reading output of tar in blocks <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 7 Jan 2003 12:43:05 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: A Good Perl Book
Message-Id: <776e0325.0301071243.3b1484d4@posting.google.com>
"Steve C" <sjcole@hotmail.com> wrote in message news:<1041892886.117181@ananke.eclipse.net.uk>...
> Hiya Folks,
>
> I'm just about to order the O'Reilly book: Programming Perl (Authors Larry
> Wall, Tom Christiansen, Jon Orwant)
> I know there's plenty of online material - but you know, I like to be able
> to read something in the local pub / bar ! (sad !!)
>
> Is this book to be recommended by the many perl gurus on this NG, or should
> I be considering something different ?
> For information: I have only ever programmed in PASCAL, BASIC, COBOL, Visual
> Basic (Arrgghh!) and more recntly dabbled with PHP4
>
> Many Thanks
>
> Steve C.
Well at best I'm a guru-in-training, but I like the "Perl in a
Nutshell" by O'Reilly press, authors Siever et al.
It's not as wordy (or witty) as "Camel" but it seems to always have
what I'm looking for and I find it quickly.
The intro is particularly good reading, and generally I'm to the point
now in functions where the only time I need info is to refresh my
memory on argument order (less, which comes first in push??) if I
haven't used it in awhile.
It's called a "Desktop Quick Reference" but it's over 650 pages long!
So it's no pcoket reference unless you have particularly deep pockets
like Bill Gates or something.
I managed to score this little gem at a local bookstore on the
clearance shelf for $9.99, and I love it.
Cheers, hope this gave you another alternative,
Gx
------------------------------
Date: Tue, 07 Jan 2003 22:09:28 GMT
From: c-blair@uiuc.edu (Charles Blair)
Subject: Re: A Good Perl Book
Message-Id: <seIS9.11741$Vf3.122429@vixen.cso.uiuc.edu>
The original poster indicated he had programmed in several languages
other than C. I would suggest practice with some of the simpler
parts of C (the loop constructs especially) might be helpful,
skipping pointers and structures.
------------------------------
Date: 7 Jan 2003 11:41:40 -0800
From: web_tur@yahoo.com (web tur)
Subject: autoresponse email
Message-Id: <5e61b5b9.0301071141.1cbc2224@posting.google.com>
How can I run a perl script after receiving an email. Where can I find some solution
Best Regards
------------------------------
Date: Tue, 07 Jan 2003 20:00:36 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: autoresponse email
Message-Id: <3E1B3112.90504@dev.null>
web tur wrote:
> How can I run a perl script after receiving an email. Where can I find some solution
>
> Best Regards
>
Use the Net::POP3 module to check your e-mail. If your mailbox is empty,
do nothing, otherwise send an autoresponse (using something like
Net::SMTP).
------------------------------
Date: Wed, 8 Jan 2003 08:38:05 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: autoresponse email
Message-Id: <avfhms$f03c8$1@ID-172104.news.dfncis.de>
"web tur" <web_tur@yahoo.com> wrote in message
news:5e61b5b9.0301071141.1cbc2224@posting.google.com...
> How can I run a perl script after receiving an email. Where can I find
some solution
Your question is very vague. Perhaps procmail?
------------------------------
Date: 7 Jan 2003 14:27:50 -0800
From: web_tur@yahoo.com (web tur)
Subject: Re: autoresponse email
Message-Id: <5e61b5b9.0301071427.40fbac0@posting.google.com>
Andras Malatinszky <nobody@dev.null> wrote in message news:<3E1B3112.90504@dev.null>...
> web tur wrote:
>
> > How can I run a perl script after receiving an email. Where can I find some solution
> >
> > Best Regards
> >
>
> Use the Net::POP3 module to check your e-mail. If your mailbox is empty,
> do nothing, otherwise send an autoresponse (using something like
> Net::SMTP).
But if I use pop3, I should run that script ever minutes to find
coming email. I want some autoresponse when email arrive, it will run
script
------------------------------
Date: Tue, 07 Jan 2003 17:55:33 GMT
From: <mouseslinger@hotmail.com>
Subject: Re: error with @ sign
Message-Id: <pwES9.480015$GR5.180949@rwcrnsc51.ops.asp.att.net>
"Mac" <schuckm@emigrant.com> wrote in message
news:3d9b1ac6.0301061356.7e27a7fa@posting.google.com...
> I am writing out html with the perl print funtion and am getting and
> error when I use the "@" sign. I figured this may be because
You need to make sure you escape the "@" symbol with a backslash
So instead of using just "@" you would need to use "\@".
Hope this helps you.
David
http://www.cgiwebsite.com
------------------------------
Date: Tue, 7 Jan 2003 12:45:51 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: error with @ sign
Message-Id: <slrnb1m82v.h15.tadmc@magna.augustmail.com>
Mac <schuckm@emigrant.com> wrote:
> I am writing out html with the perl print funtion and am getting and
> error when I use the "@" sign.
What error are you getting?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 7 Jan 2003 12:45:34 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: error with @ sign
Message-Id: <776e0325.0301071245.1e5f8c1@posting.google.com>
schuckm@emigrant.com (Mac) wrote in message news:<3d9b1ac6.0301061356.7e27a7fa@posting.google.com>...
> I am writing out html with the perl print funtion and am getting and
> error when I use the "@" sign. I figured this may be because
Enclose your argument to print within (') quotes instead of (") and
you won't have to worry about escapes (or see function qq). This will
only work if you don't have variables you need to interpolate within
the string.
Cheers,
Gx
------------------------------
Date: Tue, 07 Jan 2003 17:56:19 +0100
From: oe <olli2@biop.uni-hannover.de>
Subject: file size limits of perl Net::ftp
Message-Id: <avf0rk$qba$1@newsserver.rrzn.uni-hannover.de>
Happy new year,
I've a question concerning perl with special regard to Net::FTP. Are
there any limits in file size ? I want to do ftp->put command of a pipe
which is the output of a tar command. It works well, but if the tar
command produces more then 10 GB output, the put command fails. If I do
it by hand on the linux shell (without piping but with an intermediate
file) it works well.
Thanks for your answers,
Olli
------------------------------
Date: 7 Jan 2003 12:09:12 -0800
From: mehul111@yahoo.com (Mehul)
Subject: Find fixed drives in BATCH file or a PERL script
Message-Id: <e743165d.0301071209.2d92333a@posting.google.com>
Hi all,
Is there any way to determine the fix drives and network mapped
drives on a computer from a batch file or a perl script?
Thanks,
-Mehul
------------------------------
Date: 7 Jan 2003 20:28:15 GMT
From: Stephen Patterson <s.patterson@freeuk.com>
Subject: Re: Find fixed drives in BATCH file or a PERL script
Message-Id: <slrnb1me2p.2jr.s.patterson@eccles.localdomain>
On 7 Jan 2003 12:09:12 -0800, Mehul wrote:
> Hi all,
> Is there any way to determine the fix drives and network mapped
> drives on a computer from a batch file or a perl script?
The fixed drive letters are probably somewhere in the registry (and
probably a different place for each windows version). You should be
able to get network drives bu grepping `net use` for '+d:'
--
Stephen Patterson http://www.lexx.uklinux.net http://patter.mine.nu
steve@SPAM.lexx.uklinux.net remove SPAM to reply
Linux Counter No: 142831 GPG Public key: 252B8B37
Last one down the pub's an MCSE
------------------------------
Date: 7 Jan 2003 13:47:12 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Find fixed drives in BATCH file or a PERL script
Message-Id: <3e1b4ae0@news.victoria.tc.ca>
Stephen Patterson (s.patterson@freeuk.com) wrote:
: On 7 Jan 2003 12:09:12 -0800, Mehul wrote:
: > Hi all,
: > Is there any way to determine the fix drives and network mapped
: > drives on a computer from a batch file or a perl script?
: The fixed drive letters are probably somewhere in the registry (and
: probably a different place for each windows version). You should be
: able to get network drives bu grepping `net use` for '+d:'
this bat file displays the fixed drives, and could easily be modified to
display other things.
@echo %__DEBUG% OFF
perl -x -S %0.bat
goto done
#!perl
@used = map {m/\b([A-Z]):/} `net use`;
@used{@used}=@used;
@subst = map {m/^([A-Z]):/} `subst`;
@subst{@subst}=@subst;
foreach $drive ('C' .. 'Z')
{ next if $used{$drive} or $subst{$drive};
push @drives , $drive if chdir "$drive:";
}
print "@drives";
__END__
:done
------------------------------
Date: 07 Jan 2003 16:44:36 GMT
From: ctcgag@hotmail.com
Subject: Re: finding largest repeat values in array
Message-Id: <20030107114436.822$hA@newsreader.com>
hugo <hugo@geoinformex.com> wrote:
> Hi
>
> I have an array which often contains the same values, i.e.
>
> myArray[0] = "a";
> myArray[1] = "b";
> myArray[2] = "b";
> myArray[3] = "c";
> myArray[4] = "c";
> myArray[5] = "c";
> myArray[6] = "c";
I infer this array will always be in sorted order. I also assume
you have some valid but unstated reason for not using a hash.
> I would like to find the greatest number of identical values in this
> array, which, in the above example is 4, as there are 4 values "c".
>
> I have tried this using a loop, i.e.
>
> for ($i =0; $i < @myArray; $i++) {
> if (myArray[$i] eq myArray[$i -1]) {
> $repeat++;
> }
> }
The first time through the loop, you compare element zero to element
$#myArray.
> But this does not work as repeat will also add to itself when the array
> contains "b", in the example above.
You need to reset repeat, and capture the greatest value.
my $most=-1;
my $repeat=1;
for my $i (1..@myArray) {
if (myArray[$i] eq myArray[$i -1]) {
$repeat++;
}
else {
$most=$repeat if $repeat>$most;
$repeat=1;
};
};
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Tue, 07 Jan 2003 21:20:21 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: finding largest repreat value in an array
Message-Id: <mbudash-94BB2C.13202007012003@typhoon.sonic.net>
In article <ave5kn$t5c$1@mamenchi.zrz.TU-Berlin.DE>,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> Michael Budash <mbudash@sonic.net> wrote in comp.lang.perl.misc:
> > In article <3E1A2B58.5020501@geoinformex.com>,
> > hugo <hugo@geoinformex.com> wrote:
> >
> > > Hi
> > >
> > > I have an array which often contains the same values, i.e.
> > >
> > > myArray[0] = "a";
> > > myArray[1] = "b";
> > > myArray[2] = "b";
> > > myArray[3] = "c";
> > > myArray[4] = "c";
> > > myArray[5] = "c";
> > > myArray[6] = "c";
> > >
> > > I would like to find the greatest number of identical values in this
> > > array, which, in the above example is 4, as there are 4 values "c".
> > >
> > > I have tried this using a loop, i.e.
> > >
> > > for ($i =0; $i < @myArray; $i++) {
> > > if (myArray[$i] eq myArray[$i -1]) {
> > > $repeat++;
> > > }
> > > }
> > >
> > > But this does not work as repeat will also add to itself when the array
> > > contains "b", in the example above.
> > >
> > > Can anyone help? Any help, particularly a code example, will be greatly
> > > appreciated.
> > >
> > > Thanks
> > >
> > > Hugo
> >
> > you don't say what to do if two or more have the same numbers of
> > occurences, but ... here is one way:
> >
> > my @myarray = qw/a b b c c c c/;
> >
> > my %myhash;
> >
> > $myhash{$_}++ foreach @myarray;
> >
> > print "greatest is: ",
> > (sort { $myhash{$b} <=> $myhash{$a} } keys %myhash)[0]
> ^
> comma is missing here
> > "\n";
yikes! thanks...
>
> Sorting is generally not the best way to find a maximum.
i had the feeling, i was just being lazy... 8^\
>
> my ( $top, $max) = each %myhash;
> while ( my ( $key, $freq) = each %myhash ) {
> ( $top, $max) = ( $key, $freq) if $freq > $max;
> }
>
> print "Most frequent key is $top\n";
>
> It's more code, and not necessarily faster for small problems,
> but it finds the maximum in a single pass over n keys. Sorting
> takes n*log n time and will be slower for large n.
>
> Anno
good call - thanks
------------------------------
Date: Tue, 07 Jan 2003 08:45:43 -0800
From: TruthXayer <truthxayer@yahoo.com>
To: sfarris9@insightbb.com
Subject: Re: insert newlines in a long string
Message-Id: <3E1B0437.50602@yahoo.com>
Text::Wrap has some bugs and strange behaviour,
Text::Format is cleaner and recomended...if you do lot of formatting...
steven farris wrote:
> steven farris wrote:
>
>
>>Hello, how could i take a long string in perl
>>and insert newlines at the whitespace nearest
>>to 80 chars? So a string that contains 320 chars
>>would have roughly 5 newlines inserted into
>>it.
>
>
> Thanks for all the suggestions. Obviously Text::Wrap
> is the way to go. Oddly enough, this problem is one of
> the few where a homegrown solution would be easier to
> accomplish in C where strings are arrays as opposed
> to Perl scalars.
------------------------------
Date: Tue, 07 Jan 2003 22:32:22 GMT
From: John Kingsley <jfkingsley@earthlink.net>
Subject: Need help grabbing text from multiple lines
Message-Id: <WzIS9.21902$9N5.1978729@newsread2.prod.itd.earthlink.net>
I haven't used perl in awhile and I'm having trouble writing a script
that will copy text from a file based upon custom markup (e.g., <info>
</info>). The problem is that the beginnning tag could be in one line
and the ending tag could be many lines down and I want to capture
everything in between and just that.
Can someone please point me in the right direction? Thanks!
------------------------------
Date: Tue, 07 Jan 2003 22:51:38 GMT
From: Mike Hunter <mthunter@students.uiuc.edu>
Subject: Re: Need help grabbing text from multiple lines
Message-Id: <slrnb1mmlc.q3q.mthunter@ux5.cso.uiuc.edu>
On Tue, 07 Jan 2003 22:32:22 GMT, John Kingsley wrote:
> I haven't used perl in awhile and I'm having trouble writing a script
> that will copy text from a file based upon custom markup (e.g., <info>
> </info>). The problem is that the beginnning tag could be in one line
> and the ending tag could be many lines down and I want to capture
> everything in between and just that.
>
> Can someone please point me in the right direction? Thanks!
You can change the record separator and then use regular expressions.
From perl.about.com:
$INPUT_RECORD_SEPARATOR This variable is used when you read data in from
a file.
The default is "\n", and lines of data are considered to be everything
up to and including "\n". But you can change it to suit the data in your
file. For instance, suppose you had the following file, "test.dat"
One\Two\Three\Four#Five\Six\Seven\Eight#
If you set $/ to "#", and then read the file, it would work like this
-------
Then something like
/\<info\>(.*)\<\/info\>/
$my_stuff = $1;
(are angle brackets special characters? I don't remember....
Mike
------------------------------
Date: Tue, 07 Jan 2003 22:56:10 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Need help grabbing text from multiple lines
Message-Id: <mbudash-3A3148.14560807012003@typhoon.sonic.net>
In article <WzIS9.21902$9N5.1978729@newsread2.prod.itd.earthlink.net>,
John Kingsley <jfkingsley@earthlink.net> wrote:
> I haven't used perl in awhile and I'm having trouble writing a script
> that will copy text from a file based upon custom markup (e.g., <info>
> </info>). The problem is that the beginnning tag could be in one line
> and the ending tag could be many lines down and I want to capture
> everything in between and just that.
>
> Can someone please point me in the right direction? Thanks!
>
perldoc -f open
perldoc perlre
more of a hint:
if ($text_from_file =~ m{<info>(.+?)</info>}s) {
$the_text = $1;
}
hth-
------------------------------
Date: 7 Jan 2003 13:40:56 -0800
From: zarkssmjkn@yahoo.com (Lee)
Subject: Nested sort
Message-Id: <261ce853.0301071340.693b024d@posting.google.com>
Hello,
Learning Perl. Browsing this group and learning more...
I need to
- Sort the fileA with the data in the <......> <Grp1-01> <Rrp1-01>
- the data under each of these group <....> also needs to be sorted.
I was able to do sort the groups using associated array but I am not
successful in doing the sort under each <.....>
I think there might be scripts which I can use to solve this issue (in
this forum already????).
Any help available? Sure there must be scripts already.
Thanks.Happy New Year.
---------------------------------------------------------------------
FileA
<Grp1-10> what-01 89 72
ma01.5 1234.4 we1-rt 12345.9 aa-s34 test01
ca02.5 4321.5 sr1_tr 45679.5 aa-wttest02
...
.
.
.
ka99.5 4321.3 sr41_tr 45679.5 aa-wt test02
<Grp2-77> what-11 39 42
va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
da02.5 2321.5 sr2_tr 45679.5 aa-wt test02
...
.
.
.
fa99.5 1321.3 sr41_tr 45679.5 aa-wttest02
<Rrp99-35> peek-21 33 44
va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
da02.5 2321.5 sr2_tr 45679.5 aa-wttest02
...
.
.
.
fa99.5 1321.3 sr41_tr 45679.5 aa-wt test02
<Rrp99-55> peek-21 33 44
va04.5 4234.4 we2-rt 12345.9 aa-s34 test01
da02.5 2321.5 sr2_tr 45679.5 aa-wttest02
...
.
.
.
fa99.5 1321.3 sr41_tr 45679.5 aa-wt test02
-----------------------------------------------------------------------------
------------------------------
Date: Tue, 7 Jan 2003 16:18:21 +0000
From: news@ttvenn.net (Matt Venn)
Subject: nested try blocks causing problems
Message-Id: <slrnb1lved.1h5.news@flop.localnet>
Hi, I've got a (what I consider weird) problem that I've spent some
time trying to work out.
I'm trying to eliminate a memory leak, which is caused by a circular
references.
I have traced a particular leak to some code that I have made sure
should never be run, and yet a circular reference is still made
there that then cannot be destroyed.
The code should make it clear (I left it at the bottom for clarity).
Running the program shows that a circular reference has been made
(because destroy comes after the program finishes rather than when
the object goes out of scope). Commenting out the child->new line
stops this from happening, even though the if( 0 ) line means it
shouldn't be run.
I'm guessing it must have something to do with eval blocks (how
the trys are implemented), but the behaviour seems broken to me.
Can anyone offer ideas/solutions to this problem?
Thanks,
Matt
#!/usr/bin/perl
package parent;
use strict;
use warnings;
use Error qw| :try |;
sub new
{
my( $class ) = @_;
my $self = {};
bless $self, $class;
#weird bit, both trys are needed, if first try is commented out
#then the if( 0 ) prevents the object being created
try
{
if( 0 )
{
try
{
warn "creating child\n";
#circular reference is made here
my $object = child->new( $self );
}
otherwise {};
}
}
otherwise {};
return $self;
}
sub DESTROY
{
warn "destroying parent\n";
}
package child;
use strict;
use warnings;
sub new
{
my( $class, $parent ) = @_;
my $self = {};
bless $self, $class;
$self->{ parent } = $parent;
return $self;
}
package main;
use strict;
use warnings;
{
parent->new();
}
warn "done\n";
__END__
------------------------------
Date: Tue, 07 Jan 2003 13:33:00 -0500
From: Alexander Stremitzer <stremitz@consultant.com>
Subject: Nicer way to pass argument to program
Message-Id: <3E1B1D5C.8050502@consultant.com>
I am running the Sybase isql utility within a Perl script. My version of
the code works, but looks cludgy. I would appreciate any help on how to
simplify my program. I mean specifically on how to pass __DATA__ as $Cmd.
#!/usr/local/bin/perl -w
use strict;
use warnings;
my $PASSWD = "password";
my $TSql;
while (<DATA>) {
$TSql = $TSql . $_;
}
my $Cmd = "/usr/bin/cat << INLINE
$TSql
INLINE";
my @Resp = `/home/sybase/bin/isql -Usa -P$PASSWD -w 256 < $Cmd`;
foreach (@Resp) {
chomp;
s/ //; # remove leading blank
if (/001.{23}/) { # only process valid UID's
print "$_\n";
}
}
__DATA__
use ims
go
select dobj_uid from examination, data_object
where examination.fld_uid = data_object.rfid and
fold_status & 6144 = 0
go
Thanks,
Alex
--
All man's miseries derive from not being able to sit quietly in a room
alone. (Pascal)
------------------------------
Date: 07 Jan 2003 14:11:40 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: Nicer way to pass argument to program
Message-Id: <xcwvg10hj0z.fsf@psi.cis.ohio-state.edu>
Alexander Stremitzer <stremitz@consultant.com> writes:
> I am running the Sybase isql utility within a Perl script. My version of
> the code works, but looks cludgy. I would appreciate any help on how to
> simplify my program. I mean specifically on how to pass __DATA__ as $Cmd.
Ok, so I'm not exactly answering the question as asked, but...
There is a better way to interact with a database in Perl. Use DBI.
'perldoc -q database' should give you a start on where to find info
about DBI. Also, check http://dbi.perl.org (which may or may not be
mentioned in the FAQ...I do not have the most recent perl available at
this moment).
Using isql within a Perl script will be cludgy regardless of how you
go about it, compared to DBI.
--
Ryan Shondell <shondell@cis.ohio-state.edu>
------------------------------
Date: Tue, 7 Jan 2003 20:23:39 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: Nicer way to pass argument to program
Message-Id: <avf9ds$j2o$00$1@news.t-online.com>
"Alexander Stremitzer" <stremitz@consultant.com> schrieb im Newsbeitrag
news:3E1B1D5C.8050502@consultant.com...
> I am running the Sybase isql utility within a Perl script. My version of
> the code works, but looks cludgy. I would appreciate any help on how to
> simplify my program. I mean specifically on how to pass __DATA__ as $Cmd.
>
> #!/usr/local/bin/perl -w
>
> use strict;
> use warnings;
>
> my $PASSWD = "password";
>
> my $TSql;
> while (<DATA>) {
> $TSql = $TSql . $_;
> }
>
> my $Cmd = "/usr/bin/cat << INLINE
> $TSql
> INLINE";
>
> my @Resp = `/home/sybase/bin/isql -Usa -P$PASSWD -w 256 < $Cmd`;
> foreach (@Resp) {
> chomp;
> s/ //; # remove leading blank
> if (/001.{23}/) { # only process valid UID's
> print "$_\n";
> }
> }
>
> __DATA__
> use ims
> go
> select dobj_uid from examination, data_object
> where examination.fld_uid = data_object.rfid and
> fold_status & 6144 = 0
> go
>
> Thanks,
> Alex
I probably do not understand fully.... Why don't you use just a HERE-string?
my $PASSWD = "password";
my $Cmd = <<here;
/home/sybase/bin/isql -Usa -P$PASSWD -w 256 < /usr/bin/cat << INLINE
use ims
go
select dobj_uid from examination, data_object
where examination.fld_uid = data_object.rfid and
fold_status & 6144 = 0
go
INLINE;
here
my @Resp = `$Cmd`;
Kindly Mike
------------------------------
Date: Tue, 7 Jan 2003 13:41:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Nicer way to pass argument to program
Message-Id: <slrnb1mbbi.h51.tadmc@magna.augustmail.com>
Alexander Stremitzer <stremitz@consultant.com> wrote:
> I am running the Sybase isql utility within a Perl script.
Why don't you use the DBI.pm module instead?
> I mean specifically on how to pass __DATA__ as $Cmd.
> my $TSql;
> while (<DATA>) {
> $TSql = $TSql . $_;
> }
>
> my $Cmd = "/usr/bin/cat << INLINE
> $TSql
> INLINE";
First lets clean up the building of the shell's here-doc:
my $Cmd = "/usr/bin/cat << INLINE\n" . $TSql . "\nINLINE";
Then we can eliminate the $TSql temp variable by enabling "slurp mode":
my $Cmd;
{ local $/;
$Cmd = "/usr/bin/cat << INLINE\n" . <DATA> . "\nINLINE";
}
Then eliminate the UUOC:
$Cmd = "<< INLINE\n" . <DATA> . "\nINLINE";
(and take the < redirect out of the backticks)
And the backticked command should end up looking like:
---------------------------------
/home/sybase/bin/isql -Usa -Ppassword -w 256 << INLINE
use ims
go
select dobj_uid from examination, data_object
where examination.fld_uid = data_object.rfid and
fold_status & 6144 = 0
go
INLINE
---------------------------------
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 7 Jan 2003 22:22:04 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Perl quotations problem
Message-Id: <avf0jo$ir$1@newsreader.mailgate.org>
> > I am not sure about the compatibility possibilities, but I have
> > encountered the following error when testing Perl/CGI scripts on
> > ActivePerl versus actual server running. The following is an example:
> >
> > $str1="friendlynospam"+"@"+".org";
[snip]
> > When correctly changed to
> > $str1='friendlynospam'+'@'+'.org' it amazingly works.
[snip]
I don't have Active Perl to try the problem in the same environment but can
you try
$str1 = 'friendlynospam'.'@'.'.org' #Avoid + as that's for number addition.
HTH.
------------------------------
Date: 7 Jan 2003 17:01:58 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Problem with huge dataset, 100000000 a magic number?
Message-Id: <avf166$ld8$1@pegasus.csx.cam.ac.uk>
Bart Lateur <bart.lateur@pandora.be> wrote:
>
>The odd thing is that I can't find any trace of this in perldelta (for
>5.6, 5.005, 5.004). perlfunc and perlsub don't seem to mention it,
>either. Odd.
It changed between 5.004_04 and 5.004_05:
perl5.004_04 -we 'my (undef, $x) = (1,2)'
Can't declare undef operator in my at -e line 1, near ") ="
Execution of -e aborted due to compilation errors.
perl5.004_05 -we 'my (undef, $x) = (1,2)'
(silence)
Mike Guy
------------------------------
Date: Wed, 8 Jan 2003 08:27:09 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: reading output of tar in blocks
Message-Id: <avfh1t$fakkt$1@ID-172104.news.dfncis.de>
"Marek Zawadzki" <mzawadzk@man.poznan.pl> wrote in message
news:Pine.GSO.4.44.0301071114390.6526-100000@rose.man.poznan.pl...
> Hello,
>
> I'm creating a large tar file and I want to read tar's output, split it
> into fragments and send each fragment to the remote site without making
> local copy for the entire tarball (thus split command doesn't suit me).
> I need something like this:
>
> while (read(`tar -cf - local_file`), $buffer, $BLOCK_SIZE) {
> do_something_with_buffer;
> }
>
> I'll appreciate any hints,
>
> -marek
> (also posted on alt.perl)
http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
------------------------------
Date: Tue, 07 Jan 2003 18:13:06 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: reading output of tar in blocks
Message-Id: <3E1B5F02.AA133EEC@earthlink.net>
Marek Zawadzki wrote:
[snip]
> I've found the solution already though:
>
> open(TAR, "tar -cf - $local_file|");
>
> and then I'm reading from TAR, splitting the output and sending pieces
> one by one.
>
> Any comments to this ($local_file will be large -- often more than 1GB
> -- don't want to eat too much memory) aprectiated.
> As well as a different approach.
you might want to change the command line to:
open(TAR, "tar -cf - $local_file | gzip - - |");
Which will result in the tar data getting compressed.
The remote end, of course, needs to pass the bytes through gunzip (or
'gzip -u') before sending them to tar. Eg:
open(UNTAR, "| gunzip | tar -xf -");
... recieve ftp files, print them to UNTAR filehandle ...
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4359
***************************************