[16182] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3594 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 10 18:48:53 2000

Date: Mon, 10 Jul 2000 15:48:42 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963269322-v9-i3594@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 10 Jul 2000     Volume: 9 Number: 3594

Today's topics:
        qx vs. backticks (was:  Perl for Win32 Question) <lauren_smith13@hotmail.com>
    Re: qx vs. backticks (was:  Perl for Win32 Question) <aqumsieh@hyperchip.com>
    Re: qx vs. backticks (was:  Perl for Win32 Question) <care227@attglobal.net>
    Re: qx vs. backticks (was:  Perl for Win32 Question) <care227@attglobal.net>
    Re: qx vs. backticks (was:  Perl for Win32 Question) <aqumsieh@hyperchip.com>
    Re: qx vs. backticks (was:  Perl for Win32 Question) <aqumsieh@hyperchip.com>
    Re: qx vs. backticks (was:  Perl for Win32 Question) <care227@attglobal.net>
        Re-directing dos stderr stdout to file. How? (Steve A. Taylor)
    Re: Re-directing dos stderr stdout to file. How? (Tad McClellan)
    Re: Re-directing dos stderr stdout to file. How? <bwalton@rochester.rr.com>
    Re: Re-directing dos stderr stdout to file. How? (Steve A. Taylor)
    Re: Re-directing dos stderr stdout to file. How? (Steve A. Taylor)
    Re: Re-directing dos stderr stdout to file. How? <bwalton@rochester.rr.com>
        Read 2 databases <todd@mrnoitall.com>
    Re: Read 2 databases <care227@attglobal.net>
    Re: Read 2 databases (Abigail)
    Re: Read 2 databases <uri@sysarch.com>
    Re: Read file after writing it? mwarne@my-deja.com
    Re: Read file after writing it? mwarne@my-deja.com
    Re: Reading a file without <CR><LF> (newbie!!!) <lr@hpl.hp.com>
    Re: Reading a file without <CR><LF> (newbie!!!) <dan@tuatha.sidhe.org>
        reading from a pipe (Alex Graf)
        Redirect messages to a file martinru@my-deja.com
    Re: Redirect messages to a file undergronk@yahoo.com
    Re: Redirect messages to a file martinru@my-deja.com
    Re: Redirect messages to a file <flavell@mail.cern.ch>
    Re: Redirect messages to a file undergronk@yahoo.com
    Re: Redirect messages to a file <nnickee@nnickee.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 7 Jul 2000 13:49:52 -0700
From: "Lauren Smith" <lauren_smith13@hotmail.com>
Subject: qx vs. backticks (was:  Perl for Win32 Question)
Message-Id: <8k5fqc$2m9$1@brokaw.wa.com>


Drew Simonis <care227@attglobal.net> wrote in message
news:39662CD2.8D908506@attglobal.net...
> Lauren Smith wrote:
> >
> > system ('c:\utils\date');
> >
> > system ("c:/utils/date");
> >
>
> What about:
>
> my $date = qx'c:\utils\date';
>
> so that he can actually get the output of the command instead of
> just the exit status?

Far be it from me to question p5p, but isn't that the same as:

my $data = `c:/utils/date`;

?

What was the impetus to add a 'qx' operator?  Was it just to add a generic
quote-like operator?

Lauren







------------------------------

Date: Fri, 07 Jul 2000 21:16:05 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: qx vs. backticks (was:  Perl for Win32 Question)
Message-Id: <7asntlljyg.fsf@merlin.hyperchip.com>


"Lauren Smith" <lauren_smith13@hotmail.com> writes:

> Drew Simonis <care227@attglobal.net> wrote in message
> news:39662CD2.8D908506@attglobal.net...
> > Lauren Smith wrote:
> > >
> > > system ('c:\utils\date');
> > >
> > > system ("c:/utils/date");
> > >
> >
> > What about:
> >
> > my $date = qx'c:\utils\date';
> >
> > so that he can actually get the output of the command instead of
> > just the exit status?
> 
> Far be it from me to question p5p, but isn't that the same as:
> 
> my $data = `c:/utils/date`;
> 
> ?

Yep.

> What was the impetus to add a 'qx' operator?  Was it just to add a generic
> quote-like operator?

Yes. It is just Another Way To Do It (AWTDI). Similar to qq() and q().

--Ala


------------------------------

Date: Fri, 07 Jul 2000 17:33:49 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: qx vs. backticks (was:  Perl for Win32 Question)
Message-Id: <39664CBD.3E6879FA@attglobal.net>

Lauren Smith wrote:
> 
> 
> Far be it from me to question p5p, but isn't that the same as:
> 
> my $data = `c:/utils/date`;
> 
> ?
> 
> What was the impetus to add a 'qx' operator?  Was it just to add a generic
> quote-like operator?
> 

From the perlop documentation:

Customary  Generic   Meaning        Interpolates
``         qx{}      Command        yes (unless '' is delimiter)

Using qx'' allows things not to interpolate =)


------------------------------

Date: Fri, 07 Jul 2000 17:40:01 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: qx vs. backticks (was:  Perl for Win32 Question)
Message-Id: <39664E31.174C248A@attglobal.net>

Ala Qumsieh wrote:
> 
> >
> > Far be it from me to question p5p, but isn't that the same as:
> >
> > my $data = `c:/utils/date`;
> >
> > ?
> 
> Yep.

Nope.

> 
> > What was the impetus to add a 'qx' operator?  Was it just to add a generic
> > quote-like operator?
> 
> Yes. It is just Another Way To Do It (AWTDI). Similar to qq() and q().


The difference is qx with single quote delimiter does not interpolate 
special chars and variables, where backticks do.  The following snipet 
demonstrates this:

#!/usr/local/bin/perl -w
use strict;

my $program = 'who am i';

my $backtick = `$program`;
print $backtick,"\n";

my $qxsingle = qx'$program';
print $qxsingle,"\n";


------------------------------

Date: Mon, 10 Jul 2000 14:14:17 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: qx vs. backticks (was:  Perl for Win32 Question)
Message-Id: <7an1jqkr6u.fsf@merlin.hyperchip.com>


Drew Simonis <care227@attglobal.net> writes:

> Ala Qumsieh wrote:
> > 
> > >
> > > Far be it from me to question p5p, but isn't that the same as:
> > >
> > > my $data = `c:/utils/date`;
> > >
> > > ?
> > 
> > Yep.
> 
> Nope.

Nope. I stick to my old answer of 'Yep' (with slight modifications :)

> > 
> > > What was the impetus to add a 'qx' operator?  Was it just to add a
> generic 
> > > quote-like operator?
> > 
> > Yes. It is just Another Way To Do It (AWTDI). Similar to qq() and q().
> 
> 
> The difference is qx with single quote delimiter does not interpolate 
> special chars and variables, where backticks do.  The following snipet 
> demonstrates this:
> 
> #!/usr/local/bin/perl -w
> use strict;
> 
> my $program = 'who am i';
> 
> my $backtick = `$program`;
> print $backtick,"\n";
> 
> my $qxsingle = qx'$program';
> print $qxsingle,"\n";

You are cheating here. qx() has a property that is not available to
backticks. From perlop:

               Using single-quote as a delimiter protects the
               command from Perl's double-quote interpolation,
               passing it on to the shell instead:

                   $perl_info  = qx(ps $$);        # that's Perl's $$
                   $shell_info = qx'ps $$';        # that's the new
                                                   #  shell's $$

So, qx() does behave identically to backticks unless you use
single-quotes as the delimiter in which case qx() will not interpolate
any variables.

--Ala


------------------------------

Date: Mon, 10 Jul 2000 14:18:26 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: qx vs. backticks (was:  Perl for Win32 Question)
Message-Id: <7ak8eukqzx.fsf@merlin.hyperchip.com>


Ala Qumsieh <aqumsieh@hyperchip.com> writes:

> Drew Simonis <care227@attglobal.net> writes:

 ...

> > The difference is qx with single quote delimiter does not interpolate 
> > special chars and variables, where backticks do.

 ...

> So, qx() does behave identically to backticks unless you use
> single-quotes as the delimiter in which case qx() will not interpolate
> any variables.

Coming to think about it, this is exactly what you (Drew) said. I
totally misread your response. Sorry for wasting bandwidth.

--Ala


------------------------------

Date: Mon, 10 Jul 2000 10:19:30 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: qx vs. backticks (was:  Perl for Win32 Question)
Message-Id: <3969DB72.500CA1C5@attglobal.net>

Ala Qumsieh wrote:
> 
> You are cheating here. qx() has a property that is not available to
> backticks. From perlop:

Right, but that slight difference was what I cited as a reason to 
use qx'' (notice I've always specified qx'' and not qx{} or qx() or..)

> 
>                Using single-quote as a delimiter protects the
>                command from Perl's double-quote interpolation,
>                passing it on to the shell instead:
> 
>                    $perl_info  = qx(ps $$);        # that's Perl's $$
>                    $shell_info = qx'ps $$';        # that's the new
>                                                    #  shell's $$
> 
> So, qx() does behave identically to backticks unless you use
> single-quotes as the delimiter in which case qx() will not interpolate
> any variables.

Exactly the point of the question.  I advised the OP to use qx''
to capture the output of the command as you would using backticks,
AND to abrogate the use of special escape sequences.  Its a best 
of both worlds type of thing!  =)  So, while the special use of 
qx might not have been the reason that it was added, it sure is a 
compelling reason to use it in cases such as this.


------------------------------

Date: Sat, 08 Jul 2000 17:04:38 GMT
From: an400@freenet.carleton.ca (Steve A. Taylor)
Subject: Re-directing dos stderr stdout to file. How?
Message-Id: <39675bbd.11018721@news.ncf.carleton.ca>

Using dos under win95b, executing 

find2perl.bat > temp.txt

prints the find2perl.bat  help message to screen, and creates an empty
'temp.txt' file.  What commands or utilities will allow me to capture
the command output (dos stderr/stdout) to a file?





------------------------------

Date: Sat, 8 Jul 2000 13:01:01 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Re-directing dos stderr stdout to file. How?
Message-Id: <slrn8menid.p1d.tadmc@magna.metronet.com>

On Sat, 08 Jul 2000 17:04:38 GMT, Steve A. Taylor <an400@freenet.carleton.ca> wrote:

>What commands or utilities will allow me to capture
>the command output (dos stderr/stdout) to a file?
                         ^^^^^^

   perldoc -q STDERR


   "How can I capture STDERR from an external command?"


You are expected to check the Perl FAQ *before* posting
to the Perl newsgroup.


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Sat, 08 Jul 2000 23:59:29 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Re-directing dos stderr stdout to file. How?
Message-Id: <3967C0A5.D7546B7E@rochester.rr.com>

"Steve A. Taylor" wrote:
> 
> Using dos under win95b, executing
> 
> find2perl.bat > temp.txt
> 
> prints the find2perl.bat  help message to screen, and creates an empty
> 'temp.txt' file.  What commands or utilities will allow me to capture
> the command output (dos stderr/stdout) to a file?

Isn't the Windoze command "shell" lovely?  If you redirect the output of
a .bat file, the output of the commands listed in the .bat file are not
redirected, unless they are directly executed by the "shell" itself
(like echo, for example).  BTW, I think it is a misnomer to say Windoze
has a STDERR I/O stream.  Maybe if you installed Cygwin and used their
bash shell?  But that executes bash scripts, not .bat files.  Your
second best bet is copy/paste (oops, in the command window, that would
be "mark"/paste).  Your best bet is to switch to Linux.

Note that your question really has nothing to do with Perl, so you might
be better off asking in some Windoze newsgroup.
-- 
Bob Walton


------------------------------

Date: Sun, 09 Jul 2000 04:13:18 GMT
From: an400@freenet.carleton.ca (Steve A. Taylor)
Subject: Re: Re-directing dos stderr stdout to file. How?
Message-Id: <3967fa85.12849219@news.ncf.carleton.ca>

On Sat, 08 Jul 2000 23:59:29 GMT, Bob Walton
<bwalton@rochester.rr.com> wrote:

>"Steve A. Taylor" wrote:
>> 
>> Using dos under win95b, executing
>> 
>> find2perl.bat > temp.txt
>> 
>> prints the find2perl.bat  help message to screen, and creates an empty
>> 'temp.txt' file.  What commands or utilities will allow me to capture
>> the command output (dos stderr/stdout) to a file?
>
>Isn't the Windoze command "shell" lovely?  If you redirect the output of
>a .bat file, the output of the commands listed in the .bat file are not
>redirected, unless they are directly executed by the "shell" itself
>(like echo, for example).  BTW, I think it is a misnomer to say Windoze
>has a STDERR I/O stream.  Maybe if you installed Cygwin and used their
>bash shell?  But that executes bash scripts, not .bat files.  Your
>second best bet is copy/paste (oops, in the command window, that would
>be "mark"/paste).  Your best bet is to switch to Linux.
>
>Note that your question really has nothing to do with Perl, so you might
>be better off asking in some Windoze newsgroup.
>-- 
>Bob Walton

Thanks. It still surprises me that the author(s) of find2perl created
a batch file rendered  .. difficult or impractical .. because the
output I need is staring at me on the screen (Posting to CLPModules
may be another answer).


------------------------------

Date: Sun, 09 Jul 2000 04:13:40 GMT
From: an400@freenet.carleton.ca (Steve A. Taylor)
Subject: Re: Re-directing dos stderr stdout to file. How?
Message-Id: <3967fbf1.13213483@news.ncf.carleton.ca>

On Sat, 8 Jul 2000 13:01:01 -0400, tadmc@metronet.com (Tad McClellan)
wrote:

>On Sat, 08 Jul 2000 17:04:38 GMT, Steve A. Taylor <an400@freenet.carleton.ca> wrote:
>
>>What commands or utilities will allow me to capture
>>the command output (dos stderr/stdout) to a file?
>                         ^^^^^^
>
>   perldoc -q STDERR
>
>
>   "How can I capture STDERR from an external command?"
>
>
>You are expected to check the Perl FAQ *before* posting
>to the Perl newsgroup.
>
>
>-- 
>    Tad McClellan                          SGML Consulting
>    tadmc@metronet.com                     Perl programming
>    Fort Worth, Texas

Thanks 

So is that the expectation when I run find2perl.bat? That I will put
the command-line batch file back in a perl script, in a system command
to capture the output? Jump through two more hoops and get back to the
start.

Is there not an easier way, if it already is a batch file?


------------------------------

Date: Mon, 10 Jul 2000 02:50:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Re-directing dos stderr stdout to file. How?
Message-Id: <39693A24.FF08DC86@rochester.rr.com>

"Steve A. Taylor" wrote:
 ...
> Thanks. It still surprises me that the author(s) of find2perl created
> a batch file rendered  .. difficult or impractical .. because the
> output I need is staring at me on the screen (Posting to CLPModules
> may be another answer).

Well, I think the find2perl folks probably did about as well as can be
done and still have something that will work when you type "find2perl
 ..." in DOS.  You could nab the Perl program out of find2perl.bat (it is
just a short .bat wrapper around a standard Perl program that runs as-is
under Unix with no redirection problems) and then execute it as "perl
find2perl.pl ...", which isn't quite as nice to type, but should permit
redirection.  If you want to castigate someone, castigate Micro$loth for
the incredibly lousy job they did with their command "shell".
-- 
Bob Walton


------------------------------

Date: Wed, 05 Jul 2000 15:59:24 -0600
From: Todd Anderson <todd@mrnoitall.com>
Subject: Read 2 databases
Message-Id: <3963AEC4.4F7F9CD1@mrnoitall.com>

Hello,
Is it possible to open and read 2 separate databases  for the purpose of
populating fields?
(Example edited for post)
ie: open (PROBASE, "$provider_file_path");
  while (<PROBASE>)
    {
    $digwap = $_;
    chop $digwap;
    @figgits = split (/\|/, $digwap);
}
close (PROBASE);
#re-name variables for 2nd database
open (DATABASE, "$data_file_path");
  while (<DATABASE>)
    {
    $line = $_;
    chop $line;
    @fields = split (/\|/, $line);
}
close (DATABASE);

Thanks in advance for your help.



------------------------------

Date: Wed, 05 Jul 2000 18:02:51 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Read 2 databases
Message-Id: <3963B08B.54A75E92@attglobal.net>

Todd Anderson wrote:
> 
> Hello,
> Is it possible to open and read 2 separate databases  for the purpose of
> populating fields?
> (Example edited for post)

What was edited out?

> ie: open (PROBASE, "$provider_file_path");

I hope the omission of failure checking on the open() was part of the 
edited text.  The above should be:

open PROBASE, "$provider_file_path" or die "Can't open: $!\n";

>   while (<PROBASE>)
>     {
>     $digwap = $_;
>     chop $digwap;
>     @figgits = split (/\|/, $digwap);
> }

Do you want to get carpal tunnel and go on disability insurance?  

     chomp; #works on $_ by default.  Prefered over chop()
     @figgits = split /\|/; #also works on $_ by default.  Read 
                            #perlfunc



> close (PROBASE);
> #re-name variables for 2nd database

rename which variables and for what reason?

 open DATABASE, "$data_file_path" or die "Can't open: $!\n";
>   while (<DATABASE>)
     {
     chomp;
     @fields = split /\|/;
> }
> close (DATABASE);

Looks better shorter.  But what are you trying to accomplish?


------------------------------

Date: 05 Jul 2000 19:52:12 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: Read 2 databases
Message-Id: <slrn8m7jj1.ibb.abigail@alexandra.delanet.com>

Drew Simonis (care227@attglobal.net) wrote on MMD September MCMXCIII in
<URL:news:3963B08B.54A75E92@attglobal.net>:
@@ Todd Anderson wrote:
@@ > 
@@ > ie: open (PROBASE, "$provider_file_path");
@@ 
@@ I hope the omission of failure checking on the open() was part of the 
@@ edited text.  The above should be:
@@ 
@@ open PROBASE, "$provider_file_path" or die "Can't open: $!\n";

Bogus quotes. It should be:

   open PROBASE,  $provider_file_path  or die "Can't open: $!\n";



Abigail
-- 
echo "==== ======= ==== ======"|perl -pes/=/J/|perl -pes/==/us/|perl -pes/=/t/\
 |perl -pes/=/A/|perl -pes/=/n/|perl -pes/=/o/|perl -pes/==/th/|perl -pes/=/e/\
 |perl -pes/=/r/|perl -pes/=/P/|perl -pes/=/e/|perl -pes/==/rl/|perl -pes/=/H/\
 |perl -pes/=/a/|perl -pes/=/c/|perl -pes/=/k/|perl -pes/==/er/|perl -pes/=/./;


------------------------------

Date: Thu, 06 Jul 2000 03:38:58 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Read 2 databases
Message-Id: <x7hfa4q65p.fsf@home.sysarch.com>

>>>>> "DS" == Drew Simonis <care227@attglobal.net> writes:

  >> while (<PROBASE>)
  >> {
  >> $digwap = $_;
  >> chop $digwap;
  >> @figgits = split (/\|/, $digwap);
  >> }

  DS> Do you want to get carpal tunnel and go on disability insurance?  

  DS>      chomp; #works on $_ by default.  Prefered over chop()
  DS>      @figgits = split /\|/; #also works on $_ by default.  Read 
  DS>                             #perlfunc


and what if that file has more than one line? @figgits is overwritten
each time.

how about this:

	@figgits = map { chomp ; [ split /\|/ ] } <PROBASE> ;

then you have a real table in the array.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


------------------------------

Date: Mon, 03 Jul 2000 18:26:10 GMT
From: mwarne@my-deja.com
Subject: Re: Read file after writing it?
Message-Id: <8jqlre$ttp$1@nnrp1.deja.com>



> well, some code would be helpful.
> do you open the file with
> open FILE, "file" or die "cannot open file: $!";
> and maybe
> close FILE or die "cannot close file: $!";
>
> tina
>

Hi Tina,

Here is some code.

# flush data immediately.
# I added this to see if buffering was causing a delay in closing file
FileHandle->autoflush(1);

open (FILE, "> $fnstr") || &CgiDie("<br>Couldn't open: <br>$fnstr");
  binmode (FILE);  # write files accurately
  print FILE &remote_user();
  print FILE "\n";
  print FILE &timeNow();
  print FILE "\n";
  print FILE "$cgi_data{'note'} \n";
  close FILE;

#..... some more code and then later on...
#.
#.  @filelist was filled using readdir()
# all files in the listcan 'open' except the one written above...

   foreach $f (@filelist) {
     if (open FILE,"$ndir\\$f") {
       $i=0;
       while (<FILE>) {
         $ninfo[$i++] = $_;
       }
       close FILE;
       display_file_entry(@ninfo);
     }
   }

 Any ideas?

Thanks.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 03 Jul 2000 19:28:25 GMT
From: mwarne@my-deja.com
Subject: Re: Read file after writing it?
Message-Id: <8jqpg7$lg$1@nnrp1.deja.com>

Thanks Tina,

Your suggestion helped me find a program flow error.

Appreciate your help.

Mike.


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Tue, 4 Jul 2000 18:30:31 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading a file without <CR><LF> (newbie!!!)
Message-Id: <MPG.13cc2f9314b0705598aba5@nntp.hpl.hp.com>

In article <8jpmss$hv5$3@nntp9.atl.mindspring.net>, ebohlman@netcom.com 
says...
> belana (belana@lycosmail.com) wrote:
> : Sorry - I forgot to mention I'm working with
> : NT perl.
> 
> As Marco pointed out, you'll want to use the read() function.  Since 
> you're running on NT, you'll also want to binmode() the filehandle you're 
> reading from (although Larry Rosler would tell you that you should do 
> that even if you're running on an OS where binmode() is a no-op).

Indeed I would!  And so would the documentation for binmode() in Perl 
5.6.0.

Praise be to the appropriate Perl god for that overdue improvement.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Wed, 05 Jul 2000 19:07:09 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Reading a file without <CR><LF> (newbie!!!)
Message-Id: <xHL85.6888$cu1.17184@news1.rdc1.ct.home.com>

Marco Natoni <foo@bar.va> wrote:
> belana,

> belana wrote:
>> Sorry - I forgot to mention I'm working with NT perl.

> <cite src="perldoc -f read">
> 	=item read FILEHANDLE,SCALAR,LENGTH,OFFSET

> 	=item read FILEHANDLE,SCALAR,LENGTH

Bleah. Too much work. Instead, set $/ to be a ref to the record size and
go like this:

  $/ = \2000;
  while (<FH>) {
    # Do stuff with $_, which'll have your record in it
  }

Only works with perl 5.005 and up, but quite handy for avoiding the
relatively ugly read/sysread.

						Dan


------------------------------

Date: Thu, 06 Jul 2000 19:22:30 GMT
From: alex.graf@.....ec.gc.ca (Alex Graf)
Subject: reading from a pipe
Message-Id: <3964d743.98410144@morgoth.sfu.ca>


I am having problems reading data from a pipe.

See the line with all the # beside it? If I leave it in, the program
works fine, but if I comment it out, it doesn't work!  The &ingest sub
on the last line has trouble because the line it gets is of length 0.

I figure that the print stderr has some kind of side-effect on the
filehandle or input buffer, but I cannot figure it out from perlfaqs.
$| is only for output I thought.

Any ideas?

Alex

(btw This is actually perl version 4, on HP-UX 10.20.
I know what you're thinking, and I agree :-), but it's not by choice!)


if ($file =~ /\.gz$/)
{ $openstr = "gunzip     -c $file | $sortcmd |"; }
elsif ($file =~ /\.Z$/)
{ $openstr = "uncompress -c $file | $sortcmd |"; }
else
{ $openstr = "cat           $file | $sortcmd | "; }

print stderr "\n\ningest_file: Starting ingest of $file...\n";
print stderr "$mode, $openstr\n";       ######################

if (!(-r $file))
{
	print stderr "ingest_file: Could not find $file.
Skipping.\n";
	next INFILE;
}

if (!(open ($filehandle, $openstr)))
{
	print stderr "ingest_file: Could not open stream for $file.
Skipping.\n";
	next INFILE;
}

$ret = &ingest ($FILEHANDLE, $mode, *stats);



------------------------------

Date: Sun, 09 Jul 2000 20:18:27 GMT
From: martinru@my-deja.com
Subject: Redirect messages to a file
Message-Id: <8kammk$2pb$1@nnrp2.deja.com>

I am writing a Perl program that is giving me more errors than can fit on the
screen. I am running it from the MS-DOS command line (Windows 98).

Is there a way to have those errors redirected to an output file so that I
can see the errors that are being rolled off the screen? -Thanks.




Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 10 Jul 2000 08:31:08 GMT
From: undergronk@yahoo.com
Subject: Re: Redirect messages to a file
Message-Id: <8kc1kd$7vq$1@nnrp1.deja.com>

In article <8kammk$2pb$1@nnrp2.deja.com>, martinru@my-deja.com wrote:
> I am writing a Perl program that is giving me more errors
> than can fit on the screen. I am running it from the MS-DOS command
> line (Windows 98).
>
> Is there a way to have those errors redirected to an output file
> so that I can see the errors that are being rolled off the screen?

If these are interpreter errors, you could try redirecting 'standard
error' to a file.  Try this..

c:\> example.pl 2>errors.txt

NB  This doesn't work under NT - I'm not sure about Win98 - but give it
a go.

If the script runs OK, but produces errors when it is running, you can
open a file from inside the script and print to standard error.

Scott Kirk


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 10 Jul 2000 10:53:44 GMT
From: martinru@my-deja.com
Subject: Re: Redirect messages to a file
Message-Id: <8kc9vj$dbp$1@nnrp1.deja.com>

In article <8kc1kd$7vq$1@nnrp1.deja.com>,
  undergronk@yahoo.com wrote:
> In article <8kammk$2pb$1@nnrp2.deja.com>, martinru@my-deja.com wrote:
> > I am writing a Perl program that is giving me more errors
> > than can fit on the screen. I am running it from the MS-DOS command
> > line (Windows 98).
> >
> > Is there a way to have those errors redirected to an output file
> > so that I can see the errors that are being rolled off the screen?
>
> If these are interpreter errors, you could try redirecting 'standard
> error' to a file.  Try this..
>
> c:\> example.pl 2>errors.txt
>
> NB  This doesn't work under NT - I'm not sure about Win98 - but give
it
> a go.
>
> If the script runs OK, but produces errors when it is running, you can
> open a file from inside the script and print to standard error.
>
> Scott Kirk
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>

I tried redirecting to a file as you've illustrated above, but the
messages still scroll up the screen, and the file that is created
is empty. Any more ideas? -Thanks


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 10 Jul 2000 13:36:51 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Redirect messages to a file
Message-Id: <Pine.GHP.4.21.0007101334560.12548-100000@hpplus03.cern.ch>

On Mon, 10 Jul 2000 martinru@my-deja.com wrote:

> Any more ideas? 

You don't have a Perl language problem.  You asked an off-topic
question, and got an answer of the quality that off-topic questions
tend to get.  Ask in a group that specialises in MS Windows.

And learn to quote nicely.




------------------------------

Date: Mon, 10 Jul 2000 11:42:46 GMT
From: undergronk@yahoo.com
Subject: Re: Redirect messages to a file
Message-Id: <8kccrk$f8d$1@nnrp1.deja.com>

In article <8kc9vj$dbp$1@nnrp1.deja.com>,
  martinru@my-deja.com wrote:
> I tried redirecting to a file as you've illustrated above, but the
> messages still scroll up the screen, and the file that is created
> is empty. Any more ideas? -Thanks

Under NT you can change the screen buffer size - so you can just make
the buffer big enough to hold all the errors.  Win98 isn't so smart,
but you could try changing the initial size of the screen.  Look in the
Screen tab under Properties.

If this doesn't help, you could try to break you script down into
smaller chunks to find where the problem is.  Or post it here and maybe
someone can spot the problem for you.

Scott Kirk


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: Mon, 10 Jul 2000 07:12:22 -0500
From: Nnickee <nnickee@nnickee.com>
Subject: Re: Redirect messages to a file
Message-Id: <AD4BACD1ADB58864.D967D8768BC94A17.0E3891AFA8CD2F51@lp.airnews.net>

On Mon, 10 Jul 2000 10:53:44 GMT, someone claiming to be
martinru@my-deja.com said:

>I tried redirecting to a file as you've illustrated above, but the
>messages still scroll up the screen, and the file that is created
>is empty. Any more ideas? -Thanks


#!perl -s -w

my $output = 'error.log';

if ($ARGV[1]) {
	$output = $ARGV[1]; 
}

if (!$ARGV[0]) {
	print <<"EndOfThisBlock";
	
Usage:
	
perl err.pl file.pl output.file
	
Where file.pl is the perl script you wish to test for errors, and
output.txt is where the errors will be sent to.
	
If no output file is given, error.log will be used.
EndOfThisBlock
	exit;
}

open STDERR, ">$output" or die "Redirect didn't work! $!";

$script = $ARGV[0];
chomp($script);

$torun = "perl -c " . $script;
system ($torun);

open(TEST, $output) or die "Can't open error file $!";
$status = <TEST>;
close(TEST);

if ($status =~ m/syntax OK/) {
	print "No apparent problems with the script.\n";
}
else {
	print "He's dead, Jim....\n";
}





------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 3594
**************************************


home help back first fref pref prev next nref lref last post