[12888] in Perl-Users-Digest
Perl-Users Digest, Issue: 298 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 29 13:17:21 1999
Date: Thu, 29 Jul 1999 10:10:16 -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, 29 Jul 1999 Volume: 9 Number: 298
Today's topics:
Re: programming problem paul_rahe@cissc.canon.com
Re: Reading the binary files in Perl bidyut@yahoo.com
Re: Reading the binary files in Perl bidyut@yahoo.com
Refresh problem coming out of Perl script <jpitman@novell.com>
Split is coming Back False?!? (Mesarchm)
Re: Text::Wrap long string problem (I.J. Garlick)
Re: Using a timer on flock (Anno Siegel)
Re: Using ActiveX data objects and Win32::ole <newsreply@mpguy.freeserve.co.uk>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 27 Jul 1999 19:13:48 GMT
From: paul_rahe@cissc.canon.com
Subject: Re: programming problem
Message-Id: <379e04c6.7235203@news.cis.canon.com>
You might want to try putting your DOS commands in a BAT file and then
executing them from within your Perl script with the SYSTEM command.
Paul
On Fri, 23 Jul 1999 13:27:01 -0700, David Cassell
<cassell@mail.cor.epa.gov> wrote:
>[courtesy cc emailed to poster]
>
>yu152178@my-deja.com wrote:
>>
>> I'm writing a perl script in win95 and need to access shell command.
>> I try the following code copied from man page, but it doesn't work
>>
>> use Shell;
>>
>> $foo = echo("howdy", "<funny>", "world");
>> print "$foo";
>>
>> the error message I got is 'Bad command or file name', can any one help
>> me?
>
>You've been on win32 boxes long enough that you ought to
>recognize this error. It means that the MS-DOS shell was
>passed a command [or filename] it couldn't figure out.
>
>The code example in Shell.pm has a set of *unix* shell commands.
>Do you need to use unix commands while in win95? If so, then
>you need something besides Shell.pm, which only passes these
>on to the system's shell to decipher. You might consider using
>the Perl Power Tools [http://language.perl.com/ppt/ ] if you
>need versions of these which work in win32 also. But these
>will not fix the pipe/redirect problems of win32 shells.
>For that, you'd need to install a much better shell, or move
>to a different OS.
>
>HTH,
>David
>--
>David Cassell, OAO cassell@mail.cor.epa.gov
>Senior computing specialist
>mathematical statistician
------------------------------
Date: Thu, 29 Jul 1999 16:53:01 GMT
From: bidyut@yahoo.com
Subject: Re: Reading the binary files in Perl
Message-Id: <7nq0ta$roq$1@nnrp1.deja.com>
In article <379FA1DE.AB1B2FBD@mail.cor.epa.gov>,
David Cassell <cassell@mail.cor.epa.gov> wrote:
> bidyut@yahoo.com wrote:
> >
> > Hi there,
> > I have a problem here. I have to use Perl to read a binary file (
that
> > is produced by a C program) and parse the data out of it. Also to
> > mention that I know the length of each record.
> > So what I do is I read one record and use unpack() to parse the
data.
> > The problem is I am able to get all the string data, but unable to
get
> > any integer or float or short etc.
>
> Are you using the correct template to get those integers and
> floats out of the record? Probably not, according to my
> PSI::ESP module.
Where is this module PSI:ESP and where can I find it?
For the analysis, I am showing the code there..
<code>
$template="S S S S c41 c21 c9 I S c16 S S c9 c27 l c16 l c16 c16 c16
c80 c8 C C512 C512 C S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S C C16 C16 f f f S S C C16 C16 f f f S S
C C16 C16 f f f S S C C16 C16 f f f S S C C16 C16 c16 C C16 C16 c16 C
C16 C16 c16 C C16 C16 c16 C C16 C16 c16 C C16 C16 c16";
binmode(FILEHANDLE);
until(eof(FILEHANDLE))
{
# read the file by 2188bytes of record length
read(TNTFILEHANDLE, $buffer, 2188) || die "short record\n";
#unpack
@bytearray = unpack($template,$buffer);
foreach $i (@byt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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 1 1 0 4 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 100 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
As you can see, i am ble to extract the strings perfectly, but not the
integers and floats as you have pointed out.
I would be happy if you can help me in this direction.
Thanks
Bidyut
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 29 Jul 1999 16:52:20 GMT
From: bidyut@yahoo.com
Subject: Re: Reading the binary files in Perl
Message-Id: <7nq0s0$rhl$1@nnrp1.deja.com>
In article <379FA1DE.AB1B2FBD@mail.cor.epa.gov>,
David Cassell <cassell@mail.cor.epa.gov> wrote:
> bidyut@yahoo.com wrote:
> >
> > Hi there,
> > I have a problem here. I have to use Perl to read a binary file (
that
> > is produced by a C program) and parse the data out of it. Also to
> > mention that I know the length of each record.
> > So what I do is I read one record and use unpack() to parse the
data.
> > The problem is I am able to get all the string data, but unable to
get
> > any integer or float or short etc.
>
> Are you using the correct template to get those integers and
> floats out of the record? Probably not, according to my
> PSI::ESP module.
Where is this module PSI:ESP and where can I find it?
For the analysis, I am showing the code there..
<code>
$template="S S S S c41 c21 c9 I S c16 S S c9 c27 l c16 l c16 c16 c16
c80 c8 C C512 C512 C S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S S
S S S S S S S S S S S S S S S S C C16 C16 f f f S S C C16 C16 f f f S S
C C16 C16 f f f S S C C16 C16 f f f S S C C16 C16 c16 C C16 C16 c16 C
C16 C16 c16 C C16 C16 c16 C C16 C16 c16 C C16 C16 c16";
until(eof(FILEHANDLE))
{
# read the file by 2188bytes of record length
read(TNTFILEHANDLE, $buffer, 2188) || die "short record\n";
#unpack
@bytearray = unpack($template,$buffer);
foreach $i (@bytearray)
{
print "\n$bytearray[$i]\n";
}
print "<br><br>\n";
}
close (FILEHANDLE);
</code>
and the output is
0 1 1 1 1 1 100 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1560281088 1 0 3 1 0 0
1 1 1 1 1 1 1 0 0 1 20 20 5 TNT32 v0.2.0 1 1 1 1 1 FIREBALL EX3.2A 0
1 0 0 0 1 1 1 1 1 1 373222283930 0 1 18 18 4 1 1 1 1 1 1 1560281088 256
1 0 0 1 1 1 1 1 1 TNT32 v0.2.0 1 0 0 18 0 1 1 1 1 1 256 1 0 0 1 1 1 1
1 1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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
As you can see, i am ble to extract the strings perfectly, but not the
integers and floats as you have pointed out.
I would be happy if you can help me in this direction.
Thanks
Bidyut
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Thu, 29 Jul 1999 09:12:01 -0600
From: "Jeff Pitman" <jpitman@novell.com>
Subject: Refresh problem coming out of Perl script
Message-Id: <7npr0b$cl8$1@acs2.byu.edu>
Anyone had this problem? When the user hits back on the browser it re runs
the perl script and goes to the same "redirected" page. What I want to do
is when the user clicks on a link, the perl script takes them to a
redirected page and then when they hit Back, they go to the originating
referer page. I've tried <meta http-equiv="refresh.... and also I've tried
a mixture of JavaScript to force the browser to skip/delete the Perl script
entry in the history.
Got any solutions? It's been bugging me all week!!
Thanks,
Jeff
------------------------------
Date: 29 Jul 1999 16:31:22 GMT
From: mesarchm@aol.com (Mesarchm)
Subject: Split is coming Back False?!?
Message-Id: <19990729123122.07000.00000307@ng-ch1.aol.com>
For some reason my split function is not updating. I am getting the error "No
such file or directory". The split function works 25% of the time, but the
other 75% I get the error. Why would split be returning false (or zero). Here
is the code. Any help would be appreciated.
Thanks,
Mike
open(FILE,"$readdir\\$file") || print ERROR "couldn't open $readdir\\$file $!";
while ($line=<FILE>)
{splitit($line) || print ERROR "$!\n";}
close(FILE) || print ERROR "couldn't close $file $!";
------------------------------
Date: Thu, 29 Jul 1999 15:28:18 GMT
From: ijg@connect.org.uk (I.J. Garlick)
Subject: Re: Text::Wrap long string problem
Message-Id: <FFn1n6.8Gq@csc.liv.ac.uk>
In article <7npice$huv$1@nnrp1.deja.com>,
michaels@my-deja.com writes:
> When using Text::Wrap, if the text to be wrapped contains a string which
> is longer than $columns, it is broken up (in line with the documented
> behaviour). However, the string is also moved to the end of the text.
>
> Is there any way to avoid the long string from being moved to the end of
> the wrapped text?
This one bit me last year. Have a search of deja.com for the answers given
to me then. I honestly can't remeber them.
Also check out CPAN there are a couple of replacements there that
reportedly solve this.
What I really don't understand is why such a badly broken module is still
in the standard distribution. Afterall this bug is well known, can anyone
supply enlightenment?
--
Ian J. Garlick
ijg@csc.liv.ac.uk
In Africa some of the native tribes have a custom of beating the ground
with clubs and uttering spine chilling cries. Anthropologists call
this a form of primitive self-expression. In America they call it golf.
------------------------------
Date: 29 Jul 1999 16:47:08 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Using a timer on flock
Message-Id: <7nq0ic$1lo$1@lublin.zrz.tu-berlin.de>
<wgd@adelaide.on.net> wrote in comp.lang.perl.misc:
>Hi everyone,
>
>I've been researching the file locking issue and I have a question
>about setting up a timer to wait for a file to be unlocked.
>
>I read at the "Perl + Perl/CGI Mini FAQ", operated by Bekman Stas that
>you can use this sort of solution:
>
> $timeout=20; # in seconds
> while (-e $lock_file && (stat($lock_file))[9]+$timeout>time)
> { sleep(1);}
>
>However in Tom Christiansen's post, he says:
>
>"Never use the existence of a file C<-e $file> as a locking indication,
>because there is a race condition between the test for the existence of
>the file and its creation."
>
>So as a newbie, I ask how can you tell if a file is locked without
>using the -e indicator?
This depends on so much and you tell us so little.
Tom is of course right, if you need watertight file locking, the
lock file approach is futile. You should use flock if your system
supports it. perldoc -f flock will tell you more.
If you don't have flock, you can still do a little better than
creating a separate lock file (assuming you are on a unix system,
I don't know about others). Try to create a hard link to the
file you want to lock. This will fail if another process has
created that link already, telling you not to use it. They say
link() is an atomic action on local filesystems (as opposed to nfs),
though I have yet to see this in an authoritative source.
You'll have to make sure a process removes the lock file if it
can do so at all, otherwise you'll have spurious locks. (A big
problem this shares with the lock file approach.)
Finally, if I may insert a bit Perl here, for a timeout you could
do (untested):
my $timeout = 20;
my $sleeptime = 1;
my $lockfile = "$file.lock";
while ( not link $file, $lockfile ) {
sleep $sleeptime;
$timeout -= $sleeptime;
die "Can't access $file\n" if $timeout <= 0;
}
# got a lock
$SIG{ __DIE__} = sub { unlink $lockfile}; # perhaps catch a few others too
# process $file;
unlink $lockfile;
$SIG{ __DIE__} = 'DEFAULT';
Anno
------------------------------
Date: Thu, 29 Jul 1999 17:00:01 +0100
From: "llew" <newsreply@mpguy.freeserve.co.uk>
Subject: Re: Using ActiveX data objects and Win32::ole
Message-Id: <37a07a15@news.intensive.net>
Michel Dalle wrote in message <7npntc$p70$1@news.mch.sbs.de>...
>In article <37a058cb@news.intensive.net>, "Matthew Guy"
<newsreply@mpguy.freeserve.co.uk> wrote:
>>I am having a spot of bother at the moment, I am trying to set up a perl
>>script to access ODBC data sources via ADO, I can't seem to get at the
>>Recordset field values, here is my code below :
>[snip]
>>I am using the apache web server and ActivePerl
>>please help
>
>Here's a five-step program that will answer all your questions :
>
>1) In the ActiveState documentation (...\Perl\html\index.html), you'll
>find the ActivePerl FAQ.
>2) In there, you'll find the topic "Using OLE with Perl"
>3) Looking there, you'll see the topic "How do I use ADO ?"
>4) Reading that topic, you'll find a pointer to the 'ADO FAQ'.
>5) Click on that link and read the article.
>
>Where to find more information about the RecordSet object,
>its methods and properties ? Well, in the ADO documentation
>at the MSDN site, for instance :
>
>http://msdn.microsoft.com/library/sdkdoc/dasdk/mdao2zdv.htm
>
>You'll see that MoveFirst is not really necessary the first time,
>or that EOF will be False as long as there are any records left.
>But once you get on this level, Perl doesn't have much to do with it
>anymore...
>
>Michel.
Many thanks, got it nailed now, BTW I always put in MoveFirst - it's a habit
I got into just to make sure. As for perl not having much to do with it,
well this bit of Database access is integrated with a major text search
routine, the Database is used as an index.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 298
*************************************