[17460] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4880 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 13 18:05:56 2000

Date: Mon, 13 Nov 2000 15:05:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <974156715-v9-i4880@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 13 Nov 2000     Volume: 9 Number: 4880

Today's topics:
        about reference <greatest@i-cable.com>
    Re: about reference (Garry Williams)
    Re: about reference <not.my.real.email@bellglobal.com>
    Re: Are # comments really comments? <dpc3k@virginia.edu>
    Re: Are # comments really comments? <jeff@vpservices.com>
    Re: command line perl <uri@sysarch.com>
        Comparing textfiles <xarbosa@yahoo.com>
    Re: Comparing textfiles <soeder@ai-lab.fh-furtwangen.de>
    Re: Comparing textfiles <jeff@vpservices.com>
        compile as Bytecode or C source <anson@mail.com>
        DBI Q sternr03@popmail.med.nyu.edu
    Re: DBI Q <jeff@vpservices.com>
    Re: display shell alias in perl? (Garry Williams)
        Escaping a "$" <mflaherty2@earthlink.net>
        Get URL <jean.zoch@utoronto.ca>
    Re: Get URL <jeff@vpservices.com>
    Re: Get URL (Jerome O'Neil)
    Re: HTML print in perl script (Gwyn Judd)
        if [ -e $1 ] in Perl <yurleik@inbox.ru>
    Re: if [ -e $1 ] in Perl <jeff@vpservices.com>
    Re: if [ -e $1 ] in Perl (Jerome O'Neil)
    Re: if [ -e $1 ] in Perl <yurleik@inbox.ru>
        Newbee question, help wanted ! <rvbeek@usa.net>
    Re: Newbee question, help wanted ! <jeff@vpservices.com>
    Re: Newbee question, help wanted ! <jeff@vpservices.com>
        Piping fails within a subshell within Perl? <aarden.1@osu.edu>
    Re: Piping fails within a subshell within Perl? (Gwyn Judd)
    Re: problem making perl 5.6.0 on HPUX (M. Lavasani)
    Re: problem making perl 5.6.0 on HPUX <ronh@iainc.com>
    Re: Pushing a hash on to a stack... (Christopher Burke)
        reading post variable values from a html form with post <mark@dtekunlimited.com>
        regular expression for jpg images <dextre@pacbell.net>
    Re: regular expression for jpg images (Gwyn Judd)
        Removing New Page character from a text file <kilminjaroNOSPAM@hotmail.com>
    Re: Removing New Page character from a text file (John J. Trammell)
    Re: Simple regex problem (G.A.D.Miles)
    Re: Simple regex problem (John J. Trammell)
    Re: Simple regex problem <soeder@ai-lab.fh-furtwangen.de>
    Re: Sysread and 0x0A <tim@ipac.caltech.edu>
        Target of goto is too deeply nested <dave@iprint.com>
        Win32 - Active Directory <steve@i66.net>
    Re: Win32 - Active Directory <tshinnic@io.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Nov 2000 03:10:10 +0800
From: charlie <greatest@i-cable.com>
Subject: about reference
Message-Id: <3A103C92.933E6349@i-cable.com>


--------------4505A5AEC8B8F233C5E7AF1B
Content-Type: text/plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

Hello All, I am new to perl and have a question about reference..
I would like to search a file for some pattern and make substitution.
my code below can not make change to the file. do i miss something about
reference ?
Many Thanks.

$template = "+< c:/perl/acc.txt" ;
open(TP, $template) or die "can't open the file";
     while ($line = <TP>) {
            $line =~ s/^mget.+/yyyyyyyy/;
                           }




--------------4505A5AEC8B8F233C5E7AF1B
Content-Type: text/html; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<font face="Arial,Helvetica">Hello All, I am new to perl and have a question
about reference..</font>
<br><font face="Arial,Helvetica">I would like to search a file for some
pattern and make substitution.</font>
<br><font face="Arial,Helvetica">my code below can not make change to the
file. do i miss something about reference ?</font>
<br><font face="Arial,Helvetica">Many Thanks.</font><font face="Arial,Helvetica"></font>
<p><font face="Arial,Helvetica">$template = "+&lt; c:/perl/acc.txt" ;</font>
<br><font face="Arial,Helvetica">open(TP, $template) or die "can't open
the file";</font>
<br><font face="Arial,Helvetica">&nbsp;&nbsp;&nbsp;&nbsp; while ($line
= &lt;TP>) {</font>
<br><font face="Arial,Helvetica">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$line =~ s/^mget.+/yyyyyyyy/;</font>
<br><font face="Arial,Helvetica">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</font>
<br><font face="Arial,Helvetica"></font>&nbsp;
<br><font face="Arial,Helvetica"></font>&nbsp;
<br><font face="Arial,Helvetica"></font>&nbsp;</html>

--------------4505A5AEC8B8F233C5E7AF1B--



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

Date: Mon, 13 Nov 2000 19:36:34 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: about reference
Message-Id: <6pXP5.392$xb1.21276@eagle.america.net>

On Tue, 14 Nov 2000 03:10:10 +0800, charlie <greatest@i-cable.com>
wrote:

>--------------4505A5AEC8B8F233C5E7AF1B
>Content-Type: text/plain; charset=iso-2022-jp
>Content-Transfer-Encoding: 7bit

You should adjust your news client to send messages in plain-text.  

>Hello All, I am new to perl and have a question about reference..  I
>would like to search a file for some pattern and make substitution.
>my code below can not make change to the file. do i miss something
>about reference ?  Many Thanks.
>
>$template = "+< c:/perl/acc.txt" ;
>open(TP, $template) or die "can't open the file";
>     while ($line = <TP>) {
>            $line =~ s/^mget.+/yyyyyyyy/;
>                           }

Your question is answered in the Perl FAQ, part 5, "How do I change
one line in a file/delete a line in a file/insert a line in the middle
of a file/append to the beginning of a file?"  The FAQ is on your
system and the part you want to read is perlfaq5.  

>--------------4505A5AEC8B8F233C5E7AF1B
>Content-Type: text/html; charset=iso-2022-jp
>Content-Transfer-Encoding: 7bit
>
><!doctype html public "-//w3c//dtd html 4.0 transitional//en">
><html>

Jeesh!  Two copies in the same message.  Why?  Turn off that stupid
stuff.  

-- 
Garry Williams


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

Date: Mon, 13 Nov 2000 21:03:32 GMT
From: "MNJP" <not.my.real.email@bellglobal.com>
Subject: Re: about reference
Message-Id: <EGYP5.79101$x6.1601039@news20.bellglobal.com>



You're reading the file one line at a time into a variable, modifying the
variable, then repeating the process again.

Notice that the modifications only happen to the variable ? You need to
write that back to a file somewhere, possibly a temporary file or an array,
and when the loop is done dump the array or copy the temporary file back
over the original.

"charlie" <greatest@i-cable.com> wrote in message
news:3A103C92.933E6349@i-cable.com...
Hello All, I am new to perl and have a question about reference..
I would like to search a file for some pattern and make substitution.
my code below can not make change to the file. do i miss something about
reference ?
Many Thanks.
$template = "+< c:/perl/acc.txt" ;
open(TP, $template) or die "can't open the file";
     while ($line = <TP>) {
            $line =~ s/^mget.+/yyyyyyyy/;
                           }




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

Date: Mon, 13 Nov 2000 15:24:34 -0500
From: "Doug Coppage" <dpc3k@virginia.edu>
Subject: Re: Are # comments really comments?
Message-Id: <8upimi$nbj$1@murdoch.acc.Virginia.EDU>

Hmm. Further investigation reveals that Mr. Barclay probably has the correct
answer, although I remain suspicious. Then again, my perception seems to
fade as 5:00 PM approaches. Thank you, sir.

One day, when I have less time pressure, I will learn to use the debugger
and avoid those silly, old-fashioned print statements.

My apologies to those who are offended by the human foibles of others. :-)

---Doug C.

"Alan Barclay" <gorilla@elaine.furryape.com> wrote
> In article <8uh6n8$pp7$1@murdoch.acc.Virginia.EDU>,
> Doug Coppage <dpc3k@virginia.edu> wrote:
> >often yields "runaway string" errors several lines down. Erasing these
> >erstwhile comments from my source code eliminates the problem. Also, it
> >seems that the two characters '<' and '>' cannot be safely used in
> >commented-out print statements, either.
>
> Are you sure you're actually doing comments? If you have a missing
> quote earlier in the program, then the string will continue until it
> is matched. For example this program compiles and runs:
>
> #!/usr/local/bin/perl -w
> # this is a comment with a '
>
> print "This is the start of a print
> # this is not a comment with a "
> # this is     a comment with a "
>
>
> The quote is matched properly, even thought the line begins with a #,
> because at that time you are within a double quoted string begining
> on the print line. However, the single quote on the first line, and
> the double quote on the last line are part of true comments, and
> therefore ignored.




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

Date: Mon, 13 Nov 2000 12:36:51 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Are # comments really comments?
Message-Id: <3A1050E3.FE2E99CA@vpservices.com>

Doug Coppage wrote:
> 
> One day, when I have less time pressure, I will learn to use the debugger
> and avoid those silly, old-fashioned print statements.

Or another thing which can be awfully handy for spotting these kind of
things is a text editor that does Perl color syntax highlighting (e.g.
Emacs with cperl mode).

-- 
Jeff


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

Date: Mon, 13 Nov 2000 22:43:31 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: command line perl
Message-Id: <x7vgtrfq7k.fsf@home.sysarch.com>

>>>>> "CF" == Caron Franck <frnack.caron@infineon.com> writes:


  CF> /opt/perl -r 'my $a = 2;my $b=3;$c = ($a+$b); print $c."\n";'

  CF> this will print
  CF> 5

s/-r/-e/ ;

and my is rarely used in one liners and not needed if strict is
disabled.

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, 13 Nov 2000 21:41:08 +0100
From: "xarbosa" <xarbosa@yahoo.com>
Subject: Comparing textfiles
Message-Id: <974147897.554811@perla.rotterdam.luna.net>

Hello,

I have two textfiles with the same layout of data.
I first want to check if the names in file1 already exist in file2, and if
it does I want to compare dates to select the latest version. The entries in
the textfiles can be indefinite.

In the following example I want to see that name1.jpg exists in both files >
then compare the dates and output the name1.jpg with the newer date:

File1.txt >  name1.jpg, size, date
                 name2.jpg, size, date

File2.txt > name1.jpg, size, (newer)date
                 name3.jpg, size, date


Please don't strike down on me for posting,  it has only been 4 days of Perl
so far and I am not asking for a complete script (would be nice though) >
some good pointers would do.

Thanks in advance,
                                Xarbos

-Goals are dreams with a deadline-








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

Date: Mon, 13 Nov 2000 23:10:20 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: Re: Comparing textfiles
Message-Id: <3A1066CC.A76DC261@ai-lab.fh-furtwangen.de>

xarbosa wrote:
> 
> Hello,
> 
> I have two textfiles with the same layout of data.
> I first want to check if the names in file1 already exist in file2, and if
> it does I want to compare dates to select the latest version. The entries in
> the textfiles can be indefinite.
> 
> In the following example I want to see that name1.jpg exists in both files >
> then compare the dates and output the name1.jpg with the newer date:
> 
> File1.txt >  name1.jpg, size, date
>                  name2.jpg, size, date
> 
> File2.txt > name1.jpg, size, (newer)date
>                  name3.jpg, size, date
> 
> Please don't strike down on me for posting,  it has only been 4 days of Perl
> so far and I am not asking for a complete script (would be nice though) >
> some good pointers would do.
> 
> Thanks in advance,
>                                 Xarbos
> 
> -Goals are dreams with a deadline-

Explain your problem better and I will help you tomorrow. Good night.


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

Date: Mon, 13 Nov 2000 14:43:44 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Comparing textfiles
Message-Id: <3A106EA0.46F05F20@vpservices.com>

xarbosa wrote:
> 
> I have two textfiles with the same layout of data.
> I first want to check if the names in file1 already exist in file2, and if
> it does I want to compare dates to select the latest version. The entries in
> the textfiles can be indefinite.
> 
> In the following example I want to see that name1.jpg exists in both files >
> then compare the dates and output the name1.jpg with the newer date:
> 
> File1.txt >  name1.jpg, size, date
>                  name2.jpg, size, date
> 
> File2.txt > name1.jpg, size, (newer)date
>                  name3.jpg, size, date
> 

I'm not exactly sure this is what you want, but this snippet will print
out a list of all the images in File1.txt giving either the data as
listed in that file, or the data for that image as listed in the second
file if the data for the second file has a newer date for the same
image.  I make two further assumptions since you didn't specify: 1) that
none of the data has commas embedded in it (i.e. that commas are always
field separators) and 2) that the dates are listed in a format that can
be compared with a string comparison (e.g. yyyy-mm-dd),

my %hash;
for (<FILE1>) {
    chomp;
    my($name,$size,$date) = split /,/;
    $hash{$name}{size} = $size;
    $hash{$name}{date} = $date;
}
for (<FILE2>) {
    chomp;
    my($name,$size,$date) = split /,/;
    if ( $hash{$name}{date} lt $date ) {
        $hash{$name}{size} = $size;
        $hash{$name}{date} = $date;
    }
}
for my $name(sort keys %hash) {
    print FILE3 $name, ',', $hash{$name}{size}, ',', 
          $hash{$name}{date}, "\n";
}

-- 
Jeff


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

Date: Mon, 13 Nov 2000 14:56:40 -0500
From: Qwing Qwing <anson@mail.com>
Subject: compile as Bytecode or C source
Message-Id: <3A104778.17EBC5E3@mail.com>

I'm using ActivePerl 5.6 build 612 on Windows NT and Windows 98 (SE).
I wanna compile my scripts into Bytecode or executables with "perlcc".
I wrote a test script with just a line "print 'hello world\n';" in the
file, but I got the following error.

+ D:\programming\perl>perlcc hello.pl -b -o hello.plb
+ 
+-----------------------------------------------------------------------------
+ Compiling hello.pl:
+-----------------------------------------------------------------------------
+ Making Bytecode(hello.plb) for hello.pl!
+ C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. -MB::Stash
+     -c  + hello.pl
+ C:\Perl\bin\Perl.exe -IC:/Perl/lib -IC:/Perl/site/lib -I. +
+     -MO=Bytecode,-umain,-uattributes,-uDB,-u<none>,-uWin32 hello.pl
+ The system cannot find the file specified.
+ ERROR: In generating code for hello.pl!
+

Could someone tell me how to get through it??  Thank you.

--
Qwing Qwing


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

Date: Mon, 13 Nov 2000 20:33:22 GMT
From: sternr03@popmail.med.nyu.edu
Subject: DBI Q
Message-Id: <8upj6i$f7n$1@nnrp1.deja.com>

Does anyone know what the difference between using prepare then execure
and using do in the DBI is.

Specifically I am using Oracle. Is the difference that do commits after
the transaction and execute allows fro rollback?????

Ricki


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


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

Date: Mon, 13 Nov 2000 12:52:35 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: DBI Q
Message-Id: <3A105493.E7992638@vpservices.com>

sternr03@popmail.med.nyu.edu wrote:
> 
> Does anyone know what the difference between using prepare then execure
> and using do in the DBI is.

For a single statement, there is not much difference.  It's when you
have multiple similar statements executed in a loop that the difference
comes in.

Compare:

   for my $id( @ids ) { 
       $dbh->do("DELETE FROM $table WHERE id = '$id'");
   }

And:

   my $sth = $dbh->prepare("DELETE FROM $table WHERE id = ?");
   for my $id( @ids ) { 
       $sth->excute($id);
   }   

The first one does a "prepare" every iteration in the loop whereas the
second only prepares the statement once.  Oracle can do various kinds of
optimization when it prepares a statement and there is no sense in doing
that operation every iteration when it can be done once at the top with
the same effect.

You should also refer to the DBI docs about using do() with SELECT
statements.

> Specifically I am using Oracle. Is the difference that do commits after
> the transaction and execute allows fro rollback?????

Nope, it has nothing to do with transactions.

-- 
Jeff


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

Date: Mon, 13 Nov 2000 19:20:21 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: display shell alias in perl?
Message-Id: <V9XP5.388$xb1.21276@eagle.america.net>

On 13 Nov 2000 18:21:05 +0000, nobull@mail.com <nobull@mail.com> wrote:
>"Philip Tsai" <tsailipu@home.com> writes:
>
>> This looks to be a simple operation yet I spent hours reading documentation
>> and searching using different combinations of keywords on www.perl.com,
>> google and other search engines to no avail:  how can one assign  the value
>> of a shell "alias [some alias name]" inside a Perl program?
>
>You can't.
>
>This is covered by the FAQ: ...
>
>The aliases are part of the shell environment (although they are not
>actually environment variables[1] so are not inherited by subshells).

Some shells allow you to "inherit" aliases by defining a variable that
names a file that is sourced by each new-generation shell.  If you
place your alias commands and any other environment variable settings
you require in this file, they will be set when the shell is started.
In ksh it's ENV and in bash it's BASH_ENV.  Of course, this doesn't
help the original poster because perl invokes /bin/sh (on most Unix
systems) to implement qx//.  

The answer "You can't" is correct, of course.  

-- 
Garry Williams


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

Date: Mon, 13 Nov 2000 19:57:28 GMT
From: "Mike Flaherty" <mflaherty2@earthlink.net>
Subject: Escaping a "$"
Message-Id: <IIXP5.14606$U4.817550@newsread1.prod.itd.earthlink.net>

The following command doesn't work within Perl.  It is actually a RSH call
to run a script on a VMS machine.  On VMS, the command would be (minus
quotes) "@disk$admin:[ora_db]db_query.com  parameter_1".  However, it looks
like Perl is treating the string after the "$" as a scalar - despite the
slash.  Since $admin isn't defined (null), the file spec is invalid.

How do I get perl to recognize the correct path to my script?

print `rsh -l scriptuser my_node  \@disk\$admin:[ora_db]db_query.com
$unique_id`;

Thanks in Advance,
Mike Flaherty




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

Date: Mon, 13 Nov 2000 19:50:44 GMT
From: "Jean" <jean.zoch@utoronto.ca>
Subject: Get URL
Message-Id: <G3zB6r.KK5@campus-news-reading.utoronto.ca>

Hello,

I am looking for a module that will return the HTML code from a given URL.
For example, I would like to have a module that takes the URL of a web site,
and returns the HTML code as text, or an array of lines, or something.

Any suggestions?

Thanks,

Jean




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

Date: Mon, 13 Nov 2000 13:09:55 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Get URL
Message-Id: <3A1058A3.4E891611@vpservices.com>

Jean wrote:
> 
> 
> I am looking for a module that will return the HTML code from a given URL.
> For example, I would like to have a module that takes the URL of a web site,
> and returns the HTML code as text, or an array of lines, or something.

Use the LWP module, part of the libwww bundle, available from CPAN or
activeState.

-- 
Jeff


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

Date: Mon, 13 Nov 2000 21:19:37 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Get URL
Message-Id: <JVYP5.2399$tv3.193361@news.uswest.net>

"Jean" <jean.zoch@utoronto.ca> elucidates:
> Hello,
> 
> I am looking for a module that will return the HTML code from a given URL.
> For example, I would like to have a module that takes the URL of a web site,
> and returns the HTML code as text, or an array of lines, or something.
> 
> Any suggestions?

LWP.

perl -MLWP::Simple -e 'print get("http://www.foo.com/")'

HTH!

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: Mon, 13 Nov 2000 22:21:33 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: HTML print in perl script
Message-Id: <slrn910qbb.2so.tjla@thislove.dyndns.org>

I was shocked! How could Franky Claeys <franky.claeys@vt4.net>
say such a terrible thing:
>Hi there,
>
>Does anyone have an idea how I have to builde HTML into the perlscript
>mentioned below?
>
>I know I have to change the MIME header to text but I don't know how to wrap
>this thing into HTML.

Well if you leave the Content-type header out of the print header();
line it will use the correct (by default) content type for what you want
to do. Then all you have to do is print() some html around the image you
want to display (the CGI module has some handy methods for doing so or
you can do it by hand).

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
There are new messages.


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

Date: Mon, 13 Nov 2000 19:56:07 GMT
From: Yuri Leikind <yurleik@inbox.ru>
Subject: if [ -e $1 ] in Perl
Message-Id: <8uph0j$d6e$1@nnrp1.deja.com>

Hi all,

What would be the alternative
to Bash checking if a file exists:

if [ -e $1 ] ; then
 ...
fi

in Perl on Win32, except the ugly (to me)

if (open (F, $file)){
  close F;
  ...
}

Yuri Leikind


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


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

Date: Mon, 13 Nov 2000 12:24:13 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: if [ -e $1 ] in Perl
Message-Id: <3A104DED.35859204@vpservices.com>


Yuri Leikind wrote:
> 
> What would be the alternative
> to Bash checking if a file exists:
> 
> if [ -e $1 ] ; then


if( -e $file_name ) { ... }


See perldoc perlfunc. The file test operators are the first thing listed
in the alphabetical listing of functions.

-- 
Jeff


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

Date: Mon, 13 Nov 2000 20:27:39 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: if [ -e $1 ] in Perl
Message-Id: <%8YP5.2096$tv3.176960@news.uswest.net>

Yuri Leikind <yurleik@inbox.ru> elucidates:
> Hi all,
> 
> What would be the alternative
> to Bash checking if a file exists:
> 
> if [ -e $1 ] ; then
>  ...
> fi

Happily, Perl makes use of usefull shell things:

if(-e $file){

}
 
> in Perl on Win32, except the ugly (to me)
> 
> if (open (F, $file)){
>   close F;
>   ...
> }

Oook.

perldoc -f -X for all the file test operators.


-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: Mon, 13 Nov 2000 20:49:58 GMT
From: Yuri Leikind <yurleik@inbox.ru>
Subject: Re: if [ -e $1 ] in Perl
Message-Id: <8upk5j$g0o$1@nnrp1.deja.com>

In article <%8YP5.2096$tv3.176960@news.uswest.net>,
  jerome.oneil@360.com wrote:
> Yuri Leikind <yurleik@inbox.ru> elucidates:
> > Hi all,
> >
> > What would be the alternative
> > to Bash checking if a file exists:
> >
> > if [ -e $1 ] ; then
> >  ...
> > fi
>
> Happily, Perl makes use of usefull shell things:
>
> if(-e $file){
>
> }
>
> > in Perl on Win32, except the ugly (to me)
> >
> > if (open (F, $file)){
> >   close F;
> >   ...
> > }
>
> Oook.
>
> perldoc -f -X for all the file test operators.
>
> --
> "Civilization rests on two things: the discovery that fermentation
> produces alcohol, and the voluntary ability to inhibit defecation.
> And I put it to you, where would this splendid civilization be without
> both?" --Robertson Davies "The Rebel Angels"

Thanks!
I'm a bit ashamed ;-)

Yuri Leikind



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


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

Date: Mon, 13 Nov 2000 21:00:40 +0100
From: "Ray" <rvbeek@usa.net>
Subject: Newbee question, help wanted !
Message-Id: <u0n7fuaTAHA.282@net003s>

Newbee question:

I want to remove leading spaces from a string. The perl help directs me to
the following construction:

 $string =~ s/^\s+//;

This works perfectly as long as their is no < and > delimited part in the
string, eg
when I want to remove leading spaces from the following string:

     my $string = '   <this is a test>   ';

then everything is removed from the string and the result is an empty
string. I noticed that < and > are
operators, but it is unclear to me what they are doing. What is going on,
and more important how can
I overcome this? The result should be a string like:

             <this is a test>

Thanks!

Ray.





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

Date: Mon, 13 Nov 2000 12:17:44 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Newbee question, help wanted !
Message-Id: <3A104C68.1E5AA90D@vpservices.com>

Ray wrote:
> 
> Newbee question:

Please use a more informative subject line so others can benefit from
what you find out.  In this case "How to trim leading spaces" might have
been a good one.

> I want to remove leading spaces from a string. The perl help directs me to
> the following construction:
> 
>  $string =~ s/^\s+//;

Excellent, using the FAQ, good for you, hooray!

> This works perfectly as long as their is no < and > delimited part in the
> string, eg
> when I want to remove leading spaces from the following string:
> 
>      my $string = '   <this is a test>   ';
> 
> then everything is removed from the string and the result is an empty
> string.

Are you *sure* about that?  It works for me:

    my $string = '   <this is a test>   ';
    $string =~ s/^\s+//;
    print "[$string]";   # prints [<this is a test>   ]
    $string =~ s/\s+$//;
    print "[$string]";   # prints [<this is a test>]

-- 
Jeff


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

Date: Mon, 13 Nov 2000 12:28:03 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Newbee question, help wanted !
Message-Id: <3A104ED3.60FD59F9@vpservices.com>

Jeff Zucker wrote:
> 
> Ray wrote:
> >
> >  $string =~ s/^\s+//;
> > ...
> >
> > then everything is removed from the string and the result is an empty
> > string.

It just occured to me that you might have mistakenly capitalized the
second "s" in your regular expression which would remove all the text
because \S means "anything other than a whitespace" whereas \s means
"whitespace".

-- 
Jeff


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

Date: Mon, 13 Nov 2000 16:17:46 -0500
From: Bret Aarden <aarden.1@osu.edu>
Subject: Piping fails within a subshell within Perl?
Message-Id: <3A105A7A.DC937698@osu.edu>

A Perl script I'm writing in MacOS X PB doesn't seem to be working.
Specifically, when I spawn a subshell (using the "system" command or
backticks) with multiple commands piped together, only the first command
appears to execute, and it dumps its output directly to standard output.

Is anyone else familiar with this, and does anyone have a suggestion?

Thanks,
-Bret.



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

Date: Mon, 13 Nov 2000 22:23:09 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Piping fails within a subshell within Perl?
Message-Id: <slrn910qea.2so.tjla@thislove.dyndns.org>

I was shocked! How could Bret Aarden <aarden.1@osu.edu>
say such a terrible thing:
>A Perl script I'm writing in MacOS X PB doesn't seem to be working.
>Specifically, when I spawn a subshell (using the "system" command or
>backticks) with multiple commands piped together, only the first command
>appears to execute, and it dumps its output directly to standard output.
>
>Is anyone else familiar with this, and does anyone have a suggestion?

Maybe you should post some code. It's impossible to tell what you are
talking about.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
For every action there is an equal and opposite government program.


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

Date: 13 Nov 2000 18:34:27 GMT
From: lavasani@connect.org.uk (M. Lavasani)
Subject: Re: problem making perl 5.6.0 on HPUX
Message-Id: <8upc7j$7gb$1@oceanus.connect.org.uk>

In article <3A102100.96D22952@iainc.com>,
Ron Hartikka <ronh@iainc.com> writes:
> Can anyone tell me please the meaning of the error message at the
> bottom?
> 
> 
>>make
>  `sh  cflags libperl.a miniperlmain.o`  miniperlmain.c
>    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
>  `sh  cflags libperl.a perl.o`  perl.c
>    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
>  `sh  cflags libperl.a malloc.o`  malloc.c
>    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
>  `sh  cflags libperl.a gv.o`  gv.c
>    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
>  `sh  cflags libperl.a toke.o`  toke.c
>    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -DARG_ZERO_IS_SCRIPT -O
> +Onolimit
> cc: Perl_yylex(): error 6355: Bit vectors: Set out of memory. (6355)
> *** Error exit code 1
> 
> Sorry to tk group if this seems OT; I've had problems like this before
> and gotten help here.
> 

Post your question to  "comp.sys.hp.hpux".

ps- try to compile without "+Onolimit# option.


                __Mehdi


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

Date: Mon, 13 Nov 2000 15:57:38 -0500
From: Ron Hartikka <ronh@iainc.com>
Subject: Re: problem making perl 5.6.0 on HPUX
Message-Id: <3A1055C2.3870832B@iainc.com>

With no +Onolimit in place I get:

Optdriver: Exceeding compiler resource limits in (file or function?) ; some
optimizations skipped. Use +Onolimit if override desired.

I think the 6355 error means cc is denied memory due to insuficient swap.

How do I add swap? Do I risk making my system unusable?

"M. Lavasani" wrote:

> In article <3A102100.96D22952@iainc.com>,
> Ron Hartikka <ronh@iainc.com> writes:
> > Can anyone tell me please the meaning of the error message at the
> > bottom?
> >
> >
> >>make
> >  `sh  cflags libperl.a miniperlmain.o`  miniperlmain.c
> >    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
> >  `sh  cflags libperl.a perl.o`  perl.c
> >    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
> >  `sh  cflags libperl.a malloc.o`  malloc.c
> >    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
> >  `sh  cflags libperl.a gv.o`  gv.c
> >    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -O +Onolimit
> >  `sh  cflags libperl.a toke.o`  toke.c
> >    CCCMD =  cc -DPERL_CORE -c -D_HPUX_SOURCE -Aa -DARG_ZERO_IS_SCRIPT -O
> > +Onolimit
> > cc: Perl_yylex(): error 6355: Bit vectors: Set out of memory. (6355)
> > *** Error exit code 1
> >
> > Sorry to tk group if this seems OT; I've had problems like this before
> > and gotten help here.
> >
>
> Post your question to  "comp.sys.hp.hpux".
>
> ps- try to compile without "+Onolimit# option.
>
>                 __Mehdi



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

Date: Mon, 13 Nov 2000 21:04:12 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: Pushing a hash on to a stack...
Message-Id: <8FEC4BFA3Craznar@24.192.1.17>

usenet11274@itz.pp.sci.fi (Ilmari Karonen) wrote in <974119744.21787
@itz.pp.sci.fi>:

>Christopher.. Craznar..  Say, aren't you the guy who started that
>enormous thread over in rasfc?  I'm *not* claiming you're doing it on
>purpose, but you do have to admit that you seem to have a talent of
>getting into these situations.
>
>

I only post a request when I need to - that generally means that I post 
when I am unsure of something.

That by definition will probably increase the odds of this sort of thing 
happening. 

If I was sure of something - I would have no need to post the question 
would I ???

-- 
---
/* Christopher Burke - Spam Mail to craznar@hotmail.com
|* www.craznar.com - International Internet Writing Experiment
\* Real mail to cburke(at)craznar(dot)com


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

Date: Mon, 13 Nov 2000 12:49:16 -0800
From: "Mark D" <mark@dtekunlimited.com>
Subject: reading post variable values from a html form with post or get?
Message-Id: <WhYP5.82$oI2.44743@news.pacbell.net>

Hello all,

I new here so forgive me if I ask a question that's been answered a million
time a year ago.

What I am doing is making an html for that simply is printed into a html
page that has multiple fields

Field Names:

1First_Name
1Last_Name
1Address
1Phone
 .
 .
 .
 .
3First_Name
3Last_Name

from there I want to add some simple HTML that displays:

print "First Persons info"

print "Name:" $1First_Name ; $1Last_Name
print "Address:" $1Address

 .
 .
 .
 .
 .
print "Third Persons info"
print "Name:" $3First_Name ; $3Last_Name

etc.

Obviously, this is a simplistic representation, and I do not consider myself
a programmer, but I do have some understanding (from making changes to
personalize OP's code)
I have a freeware script that simply put all the variables into a html
screen as an array, but I need to keep the separate (not in an array, I
believe)

any examples would be greatly appreciated...

TIA

Mark




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

Date: Mon, 13 Nov 2000 13:54:50 -0800
From: "chris @ home" <dextre@pacbell.net>
Subject: regular expression for jpg images
Message-Id: <3A10632A.A41D82D@pacbell.net>

How do I convert this regular expression, which gets a handle on all
images:

<img[^>]+>

To only get image tags which are jpegs, aka, no gifs or pngs.  I just
want to get the

<img src="http://www.wherever.org/images/thisorthat.jpg">


Any help would be great.

Chris Smith



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

Date: Mon, 13 Nov 2000 22:26:09 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: regular expression for jpg images
Message-Id: <slrn910qk0.2so.tjla@thislove.dyndns.org>

I was shocked! How could chris @ home <dextre@pacbell.net>
say such a terrible thing:
>How do I convert this regular expression, which gets a handle on all
>images:
>
><img[^>]+>

No it doesn't. You really need to do proper parsing of the html to get
the tags out. I like the HTML::Parser module, although there are others
which work in different ways.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
They just buzzed and buzzed.....buzzed.


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

Date: Mon, 13 Nov 2000 15:51:13 -0600
From: Adnan <kilminjaroNOSPAM@hotmail.com>
Subject: Removing New Page character from a text file
Message-Id: <3A106251.D2D7B3E6@hotmail.com>

Hello,

 I have a text file that has newpage characters in it. If I do a 'more'
or open the file using vi these characters show up as ^L. If I open the
file using nedit editor these characters show up as <np>

 My question is, how can I get rid of these characters using a perl
script?

I have tried following but it doesnt work.

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

my $file = 'myfilenamehere';
open(FILE,"<$file") || die "Can't open `$file'! $!\n";
while(<FILE>) {
        if (m!\<np\>!) {
                s/\<np\>//;
        }
        print;
}

Replacing <np> with ^L in the script didnt work either.

I am running this script on a HP-UX B.10.20 A 9000 machine.

Thanks everyone for your time.

Adnan






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

Date: 13 Nov 2000 22:05:28 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Removing New Page character from a text file
Message-Id: <slrn90vv12.i5n.trammell@nitz.hep.umn.edu>

On Mon, 13 Nov 2000 15:51:13 -0600, Adnan <kilminjaroNOSPAM@hotmail.com> wrote:
>Hello,
>
>I have a text file that has newpage characters in it. If I do a 'more'
>or open the file using vi these characters show up as ^L. If I open the
>file using nedit editor these characters show up as <np>
>
>My question is, how can I get rid of these characters using a perl
>script?

How about:

    perl -pi.bak -e 'tr(\f)()d' filename

-- 
John J. Trammell
johntrammell@yahoo.com


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

Date: Mon, 13 Nov 2000 19:55:27 GMT
From: usad1@gadnet.com (G.A.D.Miles)
Subject: Re: Simple regex problem
Message-Id: <3a1044b2.41959345@news.newsguy.com>

On 10 Nov 2000 18:07:18 +0000, nobull@mail.com wrote:

>usad1@gadnet.com (G.A.D.Miles) writes:
>
>> I want to check whether a variable contains more than 1,000
>> characters.
>
>With a regex!?!?
>
>What's wrong with the obvious method of taking the length of the
>variable and using a numerical comparison operator?

Obvious to you maybe! I'm new to this and the books aren't helping me
here. I'm still none the wiser. What do you mean by "taking the length
of the variable"? If I knew the length the problem would be solved.

Regards,

Drummond


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

Date: 13 Nov 2000 20:56:59 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Simple regex problem
Message-Id: <slrn90vr0l.i37.trammell@nitz.hep.umn.edu>

On Fri, 10 Nov 2000 16:49:23 GMT, G.A.D.Miles <usad1@gadnet.com> wrote:
>I want to check whether a variable contains more than 1,000
>characters.
[snip]
>What should I be doing?

  if (length($var) > 1000)
  {
      # do neat stuff here
  }

-- 
John J. Trammell
johntrammell@yahoo.com


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

Date: Mon, 13 Nov 2000 23:01:26 +0100
From: Oliver =?iso-8859-1?Q?S=F6der?= <soeder@ai-lab.fh-furtwangen.de>
Subject: Re: Simple regex problem
Message-Id: <3A1064B6.3DCC2DE8@ai-lab.fh-furtwangen.de>

"G.A.D.Miles" wrote:
> 
> On 10 Nov 2000 18:07:18 +0000, nobull@mail.com wrote:
> 
> >usad1@gadnet.com (G.A.D.Miles) writes:
> >
> >> I want to check whether a variable contains more than 1,000
> >> characters.
> >
> >With a regex!?!?
> >
> >What's wrong with the obvious method of taking the length of the
> >variable and using a numerical comparison operator?
> 
> Obvious to you maybe! I'm new to this and the books aren't helping me
> here. I'm still none the wiser. What do you mean by "taking the length
> of the variable"? If I knew the length the problem would be solved.
> 
> Regards,
> 
> Drummond

Scalar or array? strlen(@array).


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

Date: Mon, 13 Nov 2000 13:19:35 -0800
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Sysread and 0x0A
Message-Id: <3A105AE7.5FC49F49@ipac.caltech.edu>

Richard Panman wrote:
> 
> I've tried that... still no luck. BTW the script is on Win98.
> 
> Here's the basics of it
> ...
> sysopen(INPUT, $inputFile,"<") or die "Couldn't open the input file\n";

If you do

use warnings;

you'll get a message warning you that that "<" should be a numeric. In this 
case, a '0'. But that's not the problem ...

> binmode INPUT;
> ...
> ...
> sysread INPUT, my $recordData,25;

                                ^^ you ask for 25 bytes

> The data in the file is (in hex):
> 
> 3200000A 23410100 0000010F 44852340 010FFFFF 2337FFFF 00FF

This is 26 bytes.

> Its comes out as
> 320000 23410100 0000010F 44852340 010FFFFF 2337FFFF 00FF

This is 25 bytes. I don't understand the byte order, but if the '0a' was 
actually at the end of the 26 bytes, then it never read it because you 
said not to. If it's a little-endian problem, then perhaps '0a' is at 
the start of the first 4 byte word and you were positioned past it?

Anyway, I can't reproduce it on linux (i386):

% perl -we
'my$x=pack"H*","3200000A234101000000010F44852340010FFFFF2337FFFF00FF"; print $x'
> xxx
% od -w26 -tx1 xxx
0000000 32 00 00 0a 23 41 01 00 00 00 01 0f 44 85 23 40 01 0f ff ff 23 37 ff ff
00 ff
0000032
% perl -wle 'sysopen X,"xxx",0 or die $!; sysread X,my($rec),25; print unpack
"H*",$rec'
3200000a234101000000010f44852340010fffff2337ffff00

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Mon, 13 Nov 2000 13:08:29 -0800
From: Dave Hodson <dave@iprint.com>
Subject: Target of goto is too deeply nested
Message-Id: <3A10584D.5B42DD1D@iprint.com>

I'm attempting to fix a bug in my code which is causing the following
DIE msg

"Target of goto is too deeply nested"

I know there is an ENV var that lets me change the # of "levels" a goto
can climb through, but I cannot find it anywhere.

Anyone know what it is?

Dave



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

Date: Mon, 13 Nov 2000 14:02:22 -0500
From: "SC" <steve@i66.net>
Subject: Win32 - Active Directory
Message-Id: <3a103b52$0$16149@wodc7nh1.news.uu.net>

Can anyone point me to a module or modules that provide API access to
windows2000 Active Directory objects?

I am trying to modify entries in user objects, and can only do so much
with NetAdmin and AdminMisc..

Any pointers appreciated..

S.




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

Date: Mon, 13 Nov 2000 22:55:10 GMT
From: Thomas L. Shinnick <tshinnic@io.com>
Subject: Re: Win32 - Active Directory
Message-Id: <oer01tg3bpgdao14d8rbcbk55it668utk8@4ax.com>

On Mon, 13 Nov 2000 14:02:22 -0500, "SC" <steve@i66.net> wrote:
>Can anyone point me to a module or modules that provide API access to
>windows2000 Active Directory objects?
>
>I am trying to modify entries in user objects, and can only do so much
>with NetAdmin and AdminMisc..

Use Win32::OLE to access ADSI.

O'Reilly books:  (Hi David!)
    _Windows 2000 Active Directory_, ISBN 1-56592-638-2 has a whole
    section on ADSI (though all of the examples are also in VB). It
    appears to be an excellent book on AD in general.

    _Perl for System Administration_, ISBN 1-56592-609-9 has part of a chapter
    devoted to ADSI and using it from Perl

Another book:
    _Windows NT/2000: ADSI Scripting for System Administration_, 
    ISBN 1-57870-219-4, is not Perl-specific but in VB.

David's book references ADSI/Perl pages at
http://public.activestate.com/authors/tobyeverett/.  Sounds like he
has code you can read...

Some more links I gave a fellow at work who used Access instead  %-P
ADSI 2.5
http://www.microsoft.com/ntserver/nts/downloads/other/ADSI25/default.asp
 and more specifically,  the APIs
http://download.microsoft.com/msdownload/adsi/2.5/ads.exe  
 and development documents and examples
http://download.microsoft.com/msdownload/adsi/2.5/sdk/x86/en/Sdk.zip  
 and the main help file
http://www.microsoft.com/ntserver/downloads/bin/nts/adsi25.chm

>
>Any pointers appreciated..
>
>S.
>


-- 
When time permits, your personal life will be exciting.
  -- Restaurant Fortune Cookie       (They know me there ...)


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

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 4880
**************************************


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