[7428] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1053 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 20 04:17:32 1997

Date: Sat, 20 Sep 97 01:00:40 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 20 Sep 1997     Volume: 8 Number: 1053

Today's topics:
     Re: Can I specify fonts? (COWBYS)
     Re: Change /etc/passwd (Jean-Damien Durand)
     Re: chop/chomp, take 2 (Tad McClellan)
     Re: chop/chomp, take 2 (Steve Lamb)
     Re: chop/chomp, take 2 <ajohnson@gpu.srv.ualberta.ca>
     Re: chop/chomp, take 2 (Steve Lamb)
     Re: chop/chomp, take 2 (Paul D. Smith)
     Re: chop/chomp, take 2 (Steve Lamb)
     Re: Confusion with chop/chomp <ajohnson@gpu.srv.ualberta.ca>
     Re: Confusion with chop/chomp (Steve Lamb)
     Converting txt2html.pl to a Perl 5 module (Christopher J. Madsen)
     Copying files <anle@ehsn3.ews.uiuc.edu>
     Re: Copying files <rra@stanford.edu>
     Re: Hash table reference in regex <bholzman@mail.earthlink.net>
     locking files over NFS <daftary@cisco.com>
     Perl and form fields (COWBYS)
     Re: Perl and form fields (Tad McClellan)
     Re: What does this error message mean? (Ilya Zakharevich)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 20 Sep 1997 03:00:33 GMT
From: cowbys@aol.com (COWBYS)
Subject: Re: Can I specify fonts?
Message-Id: <19970920030001.XAA21061@ladder01.news.aol.com>

Yeah, but can you do all of this if you are printing to a filehandle? , 
Id, like to know if anyone else does..

davef@aasp.net


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

Date: Sat, 20 Sep 1997 07:26:16 GMT
From: ddurand@hpplus16.cern.ch (Jean-Damien Durand)
To: jgloudon@bbn.com (Jason Gloudon)
Subject: Re: Change /etc/passwd
Message-Id: <EGspzs.py@news.cern.ch>


> >Is there any perl function or routine that can send the password
> >parameters (user, old password,  new password) to the passwd command?
> 
> The simplest way to do this from a language perspective is to use expect
> see http://expect.nist.gov.

  The HTTPD module (available at CPAN) is easy to use, also.

  Cheers,                      Jean-Damien.
--
       *******************************************************
       *   Jean-Damien Durand (Jean-Damien.Durand@cern.ch)   *
       *        www : http://wwwinfo.cern.ch/~ddurand/       *
       *******************************************************


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

Date: Fri, 19 Sep 1997 21:05:32 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: chop/chomp, take 2
Message-Id: <c1bvv5.bi1.ln@localhost>

Steve Lamb (morpheus@calweb.com) wrote:
: Tom,
:     Here it is:


What version of perl are you using?

The 'blah.work' does not work for me with 5.004

I don't get the 'version' on a line by itself on the line following
the '-GreydMiyu:. version' line...

Has your perl been hacked to allow dot to match a newline? (see below)


: --- SNIP "bottest.log" ---
: :GreydMiyu!morpheus@192.168.0.1 PRIVMSG #bottest :. version
: --- SNIP "bottest.log" ---

:     That is the line that the script tests.  First, the script that works.

: --- SNIP "blah.work" ---
: $channel = "#bottest";

: open(BLAH,"bottest.log");
: $line=<BLAH>;
: close(BLAH);
: ($from, $type, $remainder) = split(/ /,$line,3);
: $from =~ /^:(.*)!(.*)$/;
: $from = $1;
: $host = $2;
: print("$from $host $type\n");
: if ($type eq "PRIVMSG") # Standard messages
: {
:   ($dest, $remainder) = split(/ /,$remainder,2);
:   print("inmsg: $from $type $dest $remainder\n");  # in case of errors
:   if ($dest eq $channel)
:   {
:     print("-$from$remainder");
:     if ($remainder =~ /:\. (.*)/)
                             ^^^^   not m//s, so $1 can NEVER have a newline

:     {
: # *** Chop inside loop ***
:       chop($chopme = $1);

$chopme is now equal to 'versio' ...

Is there some reason that you are not using safe chomp()?


:       if ($chopme eq "version")
:       {
:         print("version\n");
          ^^^^^^^^^^^^^^^^^^  This doesn't print for me, as expected

:       }
:     }
:   }
: }
: --- SNIP "blah.work" ---

: Output:

: GreydMiyu morpheus@192.168.0.1 PRIVMSG
: inmsg: GreydMiyu PRIVMSG #bottest :. version

: -GreydMiyu:. version
: version

:    
:     Now two scripts that fail.

: --- SNIP "blah.fail1" ---
: $channel = "#bottest";

: open(BLAH,"bottest.log");
: $line=<BLAH>;
: close(BLAH);
: ($from, $type, $remainder) = split(/ /,$line,3);
: $from =~ /^:(.*)!(.*)$/;
: $from = $1;
: $host = $2;
: print("$from $host $type\n");
: # *** chop outside loop
: chop($remainder); 
: if ($type eq "PRIVMSG") # Standard messages
: {
:   ($dest, $remainder) = split(/ /,$remainder,2);
:   print("inmsg: $from $type $dest $remainder\n");  # in case of errors
:   if ($dest eq $channel)
:   {
:     print("-$from$remainder");
:     if ($remainder =~ /:\. (.*)/)
:     {
:       if ($1 eq "version")
:       {
:         print("version\n");
:       }
:     }
:   }
: }
: --- SNIP "blah.fail1" ---

: Output:
: GreydMiyu morpheus@192.168.0.1 PRIVMSG
: inmsg: GreydMiyu PRIVMSG #bottest :. version



Hmmm. I get a third line of output:

-GreydMiyu:. versionversion



: --- SNIP "blah.fail2" ---
: $channel = "#bottest";

: open(BLAH,"bottest.log");
: $line=<BLAH>;
: close(BLAH);
: ($from, $type, $remainder) = split(/ /,$line,3);
: $from =~ /^:(.*)!(.*)$/;
: $from = $1;
: $host = $2;
: print("$from $host $type\n");
: if ($type eq "PRIVMSG") # Standard messages
: {
:   ($dest, $remainder) = split(/ /,$remainder,2);
:   print("inmsg: $from $type $dest $remainder\n");  # in case of errors
: *** chop right before where it would be in the inner loop
:   chop($remainder);
:   if ($dest eq $channel)
:   {
:     print("-$from$remainder");
:     if ($remainder =~ /:\. (.*)/)
:     {
:       if ($1 eq "version")
:       {
:         print("version\n");
:       }
:     }
:   }
: }
: --- SNIP ---

: Output:
: GreydMiyu morpheus@192.168.0.1 PRIVMSG
: inmsg: GreydMiyu PRIVMSG #bottest :. version


Hmmmm, hmmmm.

I get a third (blank line) and fourth line of output:

-GreydMiyu:. versionversion


:     Now, let's look this over, ok?  In script 1 it works, everything is
: printed down to the version.  In script 2, the output is:

: GreydMiyu morpheus@192.168.0.1 PRIVMSG
: inmsg: GreydMiyu PRIVMSG #bottest :. version

:    It gets inside the PRIVMSG check because we have the inmsg line printed. 
: It does not, however, get into the first inner loop because there is no line
: starting with a -.

:     In script number three, the same thing occurs.  We get into the inmsg
: line, but no further.

:     Now, can you see why I say that $dest is not, or is it EVER being
: modified?  Now, do you see why, although I am going to do the chop/chomp on
: the innermost loop (which is now a subroutine) I am still miffed as to why
: it will not get past a variable which should not be modified if placed
: before that check?  It is not even getting to the check for "version", we
: know this, there is no "-" line. 


I cannot duplicate the output you have given for any of the three scripts.

Not even the 'working' one...


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: 20 Sep 97 02:29:52 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: Re: chop/chomp, take 2
Message-Id: <slrn626e2h.qi2.morpheus@death.calweb.com>

On Fri, 19 Sep 1997 21:05:32 -0500, Tad McClellan <tadmc@flash.net> wrote:
>What version of perl are you using?

This is perl, version 5.003 with EMBED
        built under linux at Jun 27 1996 21:52:16
        + suidperl security patch

>Has your perl been hacked to allow dot to match a newline? (see below)

    Not that I am aware of.

>:     if ($remainder =~ /:\. (.*)/)

>                             ^^^^   not m//s, so $1 can NEVER have a newline
>: # *** Chop inside loop ***
>:       chop($chopme = $1);

>$chopme is now equal to 'versio' ...

>Is there some reason that you are not using safe chomp()?

   No, $chopme is now equal to "version".  Yes, because chomp() wasn't
working.  The reason being is because the IRC ends likes with CR\LF.  \m\n? 
So the .* would not match the newline and chop() would kill the CR.

>:       if ($chopme eq "version")
>:       {
>:         print("version\n");
>          ^^^^^^^^^^^^^^^^^^  This doesn't print for me, as expected

    I forgot to mention that the M at the end was a CR, my apologies.  I bet
if you edit it to include the CR it will work.

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
CC: from news not wanted or appreciated| skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: Fri, 19 Sep 1997 22:06:04 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: chop/chomp, take 2
Message-Id: <34233D9C.3D498828@gpu.srv.ualberta.ca>

Steve Lamb wrote:
> 

[snip code tests]

I'd have to say that something seems broken on your machine
as I can't reproduce your output from any of your
three test scripts --- here are my results:

---script 1 output (blah.work):

GreydMiyu morpheus@192.168.0.1 PRIVMSG
inmsg: GreydMiyu PRIVMSG #bottest :. version

-GreydMiyu:. version

----------------------
---script 2 output (blah.fail1):

GreydMiyu morpheus@192.168.0.1 PRIVMSG
inmsg: GreydMiyu PRIVMSG #bottest :. version
-GreydMiyu:. versionversion

----------------------
---script 3 (blah.fail2):

GreydMiyu morpheus@192.168.0.1 PRIVMSG
inmsg: GreydMiyu PRIVMSG #bottest :. version

-GreydMiyu:. versionversion
-----------------------------------------

note, your output of script 1 (blah.work) shows a 
final "version" printed---this shouldn't be the
case if your test $line is correct... the relevant  
section:

   print("-$from$remainder");
    if ($remainder =~ /:\. (.*)/)
    {
# *** Chop inside loop ***
      chop($chopme = $1);
      if ($chopme eq "version")
      {
        print("version\n");
      }
    }

now, $1 would not have a newline at the end because (.*)
won't match a newline in your regex without /s, so 
$1 would be just "version" before chop()'ing and would
be "versio" afterwards ... unless you have some space
or other hidden character between 'version' and the end
of the line in your file.

as for your two 'failed' scripts, they work here
under both 5.00403 and 5.003

regards
andrew


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

Date: 20 Sep 97 03:44:33 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: Re: chop/chomp, take 2
Message-Id: <slrn626iej.qop.morpheus@death.calweb.com>

On Fri, 19 Sep 1997 22:06:04 -0500,
Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> wrote:
>I'd have to say that something seems broken on your machine
>as I can't reproduce your output from any of your
>three test scripts --- here are my results:

    Again, if you get the input line correct you would get the same results. 
In fact I just got a wonderful message from Paul D. Smith which explains it
all.

   The input line *MUST* have a CR (CNTL-M) at the end before the newline to
get the below results.  As Paul explained the CR was returning the cursor to
the beginning of the line and, as such, overwriting the output of the -
line.  With the chopo outside the (if $remainder =~ /: (.*)/) line it would
get the newline before the .* would and then leave the CR.  Whereas with the
chop after that line the .* would remove the newline, the chopo would remove
the CR and it would match.

   The whole mess, even you and Tom not being able to reproduce the results,
is because of that CR.

>note, your output of script 1 (blah.work) shows a 
>final "version" printed---this shouldn't be the
>case if your test $line is correct... the relevant  
>section:

    It is when you have the CR at the end because it chops down from
"version^M" to "version".

>or other hidden character between 'version' and the end
>of the line in your file.

    The CR which was there as ^M.

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
CC: from news not wanted or appreciated| skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: 19 Sep 1997 23:23:40 -0400
From: psmith@baynetworks.com (Paul D. Smith)
To: morpheus@calweb.com
Subject: Re: chop/chomp, take 2
Message-Id: <p5lo0sy8g3.fsf@baynetworks.com>

%% morpheus@calweb.com (Steve Lamb) writes:

  sl> --- SNIP "bottest.log" ---
  sl> :GreydMiyu!morpheus@192.168.0.1 PRIVMSG #bottest :. version
  sl> --- SNIP "bottest.log" ---

You forgot the most important thing; there's a \r (^M) at the end of
this line in your log.  I would have been baffled if I hadn't noticed
you showed one in a previous post.

If you leave off the ^M, everything works as you expect.

However, everything is _still_ working as it should.  You just don't
understand what you're seeing.

It's never a good idea to print debugging statements without newlines,
which you do quite often in your tests.  Also, I always print some kind
of delimiter around my variables so I can see if there're hard-to-see
chars in them, like:

  print("`$remainder'\n");

Your problem is you're forgetting that ^M is a carriage return without a
linefeed.  That means printing that char repositions your cursor to the
beginning of the line, but doesn't move you down a line.

Then, when you print some more stuff it overwrites what you printed
before.

Let's examine your first "broken" script:
   
  sl>     Now two scripts that fail.

  sl> chop($remainder); 

You've removed the \n here, but the \r (^M) is still there.

  sl>   ($dest, $remainder) = split(/ /,$remainder,2);
  sl>   print("inmsg: $from $type $dest $remainder\n");  # in case of errors
  sl>   if ($dest eq $channel)
  sl>   {
  sl>     print("-$from$remainder");

Here, $remainder has a ^M at the end, so when you print this line it
prints, but then the cursor moves back to the beginning of the line
(under the "-").

  sl>     if ($remainder =~ /:\. (.*)/)
  sl>     {
  sl>       if ($1 eq "version")

This is not true, because $1 is "version^M", not "version", so it
doesn't do this print:

  sl>         print("version\n");

So, your cursor is still sitting before the text above, and when the
perl script exits your prompt overwrites the text.  Since a line isn't
actually printed until the buffer is flushed at newline it looks like it
didn't print anything, but it really did.

If you modify your print statement to add a newline after you print the
$remainder, it will be more obvious what's happening:

  print("-$from$remainder\n");
                         ^^

  sl> GreydMiyu morpheus@192.168.0.1 PRIVMSG
  sl> inmsg: GreydMiyu PRIVMSG #bottest :. version

With the above newline change, I get the output:

  GreydMiyu morpheus@192.168.0.1 PRIVMSG
  nmsg: GreydMiyu PRIVMSG #bottest :. version
  -GreydMiyu:. version

Just as you'd expect.  No second "version" because the equality test
failed due to the ^M.

In your second "broken" script, you have the same problem:

  sl> *** chop right before where it would be in the inner loop
  sl>   chop($remainder);

Here you've removed the \n, but not the ^M.

  sl>   if ($dest eq $channel)
  sl>   {
  sl>     print("-$from$remainder");

This prints, but the cursor moves back to column 1 (under the -).

  sl>     if ($remainder =~ /:\. (.*)/)
  sl>     {
  sl>       if ($1 eq "version")

This is, again, not true because $1 is "version^M", not "version"

  sl>         print("version\n");

so this doesn't print.

Then your prompt (or the next line) prints and overwrites the "-..."
text.

Finally, look at your "working" script:

  sl>   if ($dest eq $channel)
  sl>   {
  sl>     print("-$from$remainder");

Because you haven't chopped $remainder yet, it still has both the ^M and
the \n at the end, so after the ^M moves back to column 1, the newline
is printed and it moves down a line; this means the next lines won't
overwrite what you had before.

  sl>     if ($remainder =~ /:\. (.*)/)

$1 here will get "version^M", not "version^M\n", because . never matches
newline on normal regexp.

  sl>       chop($chopme = $1);

You do the chop here, so _NOW_ your test succeeds:

  sl>       if ($chopme eq "version")

Because after the chop, $chopme is "version" instead of "version^M".

  sl>         print("version\n");

So this prints, a newline is generated, and you see "version\n" printed
out.

  sl>    It gets inside the PRIVMSG check because we have the inmsg line
  sl> printed.  It does not, however, get into the first inner loop
  sl> because there is no line starting with a -.

Yes it does.  There is no line starting with a "-" because you overwrite
it with the next line.

  sl>     In script number three, the same thing occurs.  We get into
  sl> the inmsg line, but no further.

Not true.

  sl>     Now, can you see why I say that $dest is not, or is it EVER
  sl> being modified?

I see why you say it, but you're wrong.

  sl> Now, do you see why, although I am going to do the chop/chomp on
  sl> the innermost loop (which is now a subroutine) I am still miffed
  sl> as to why it will not get past a variable which should not be
  sl> modified if placed before that check?  It is not even getting to
  sl> the check for "version", we know this, there is no "-" line.

Yes it is.  You are misinterpreting the evidence.

Perhaps a bit more rigorous testing on your part is in order next time
before you get all burnt up and start yelling at people like Tom
Phoenix; they've been hacking Perl a heck of a lot longer than you, and
if they say something is so, then I'd go back and check it 10 more times.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.


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

Date: 20 Sep 97 03:59:26 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: Re: chop/chomp, take 2
Message-Id: <slrn626jah.qop.morpheus@death.calweb.com>

On 19 Sep 1997 23:23:40 -0400, Paul D. Smith <psmith@baynetworks.com> wrote:
>You forgot the most important thing; there's a \r (^M) at the end of
>this line in your log.  I would have been baffled if I hadn't noticed
>you showed one in a previous post.

    I didn't forget that.  I was just not sure what was going on on the
insides.  You explained it quite well.

>However, everything is _still_ working as it should.  You just don't
>understand what you're seeing.

    Exactly.

>  print("`$remainder'\n");

    I've been also loogging to a file now so I can use joe to look at the
files and see any hidden characters.  Sad that the console cannot display
these characters.

>Perhaps a bit more rigorous testing on your part is in order next time
>before you get all burnt up and start yelling at people like Tom
>Phoenix; they've been hacking Perl a heck of a lot longer than you, and
>if they say something is so, then I'd go back and check it 10 more times.

    And he was saying that $dest was being modified.  Through your entire
explination that was not the case.  I *KNEW* that wasn't the case.  I don't
care if Billy-Bo-Bob down the street or the almighty god of your particular
religion tells me something false, I'm not going to change my mind on it
without a reasonable explination.  $dest being changed was not reasonable.

    What I have learned here is that the next time I post, boil the question
down first.  I thought I had done that with my first post with the snippet
of code.  I was wrong.  I shall endeavor to do better next time.  Thanks for
your help.

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
CC: from news not wanted or appreciated| skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: Fri, 19 Sep 1997 21:30:14 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Confusion with chop/chomp
Message-Id: <34233536.1784865F@gpu.srv.ualberta.ca>

Steve Lamb wrote:
> 
[snip]

well, using the essential code statements from your last post,
I'd have to agree with Tom that nothing unexpected happens...
are you saying that the following code snippet does not
work on your machine as it does on mine???

#!/usr/bin/perl -w
$channel="#bottest";
$line=":GreydMiyu!morpheus\@192.168.0.1 PRIVMSG #bottest :. version^M\n";
($from, $type, $remainder) = split(/ /,$line,3);
print "$from|$type|$remainder";
chomp($remainder);
($dest,$remainder) = split(/ /,$remainder,2);
print "$dest|$remainder\n";
if ($dest eq $channel) {
   print "no problem\n";
}
__END__

on my machine this prints:

:GreydMiyu!morpheus@192.168.0.1|PRIVMSG|#bottest :. version^M
#bottest|:. version^M
no problem

regards
andrew


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

Date: 20 Sep 97 02:51:59 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: Re: Confusion with chop/chomp
Message-Id: <slrn626fc1.qi2.morpheus@death.calweb.com>

On Fri, 19 Sep 1997 21:30:14 -0500, Andrew Johnson
<ajohnson@gpu.srv.ualberta.ca> wrote:
>work on your machine as it does on mine???

    This code works.  Mine does not.  I'd love to know why.

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
CC: from news not wanted or appreciated| skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: 19 Sep 1997 20:54:10 -0500
From: ac608@yfn.ysu.edu (Christopher J. Madsen)
Subject: Converting txt2html.pl to a Perl 5 module
Message-Id: <u7mccpx6l.fsf@yfn.ysu.edu>

I've been using Seth Golub's txt2html.pl script from
  http://www.cs.wustl.edu/~seth/txt2html/
It's very useful, but I wish it were available as a module.  I've been
considering rewriting it into one.

There are two possible approaches.  The easiest would be to take
txt2html.pl with as few changes as possible and slap a function around
it.  It would be quite simple to produce a module that just provided
  txt2html($outfile,@args)
which would be equivalent to
  system('txt2html.pl', @args)
but more efficient and with output to $outfile.  For example:

  txt2html(qw(sample.html --prebegin 0 --title Sample sample.txt));

This would require minimal changes to the existing code.  However, if I
were starting from scratch, I'd never design an interface like this.


The other approach would be to eliminate the command-line argument
processing and write new code to setup the varibles.  (Or modify the
existing code so it no longer depended on global variables.)

This would probably be done best as an object-oriented interface.

  $c = new Text::ToHTML;
  $c->set_options(...);
  $c->convert('filename');

This is what I would do if I were starting from scratch, but it would
require more work (which I don't have time to do), and would be more
likely to introduce new bugs.

I've talked to Seth about this, and he's willing to drop Perl 4
support, but I don't think he has time to do the rewrite either.


The other problem is deciding what to call it.  So far, I've thought of
  Txt2HTML  Text::HTML  Text::ToHTML  HTML::FromText
and I'm leaning towards Text::ToHTML.  Anybody else want to vote?

Is anyone interested in working on this?  I could implement the first
suggestion myself, but I don't have time right now to do an
object-oriented version.

-- 
Chris Madsen        chris_madsen@geocities.com       ac608@yfn.ysu.edu
 ------- http://www.geocities.com/SiliconValley/Heights/3222/ -------


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

Date: Fri, 19 Sep 1997 23:39:42 -0500
From: An Thi-Nguyen Le <anle@ehsn3.ews.uiuc.edu>
Subject: Copying files
Message-Id: <Pine.GSO.3.96.970919232925.28393C-100000@ehsn3.ews.uiuc.edu>

This is my first Perl program.  Don't laugh.  At least, not more than you
have to :7

Archive (gonna change the name later) is meant to create bakups (currently
of everything in the directory that isn't a directory) in the form of
directories named "bakupx", where x is the version of the bakup (entered
from command line, eventually will be figured out by the program).  No big
deal.

Everything is peachy-keen until line 33, or so perl tells me, with the
syscall to "cp": "Argument "cp" isn't numeric in syscall at archive line
33. Bad system call"  

My first question is: What does the above error message mean?
Second: Can I cp this way, or will I have to kludge up a sub to do the
copying?  

Don't worry about the other errors (command line arguments); I know about
them, but I want to get this copy thing cleaned up before I fuss around
with making the interface nicer and consistent...

Tips are also welcome.

#!/usr/local/bin/perl -w

#  archive
#     Creates a bakup of the indicated files to a directory called 
#     "bakupx" where x is the number of the bakup. 
#  usage: archive number files

#Check up on number of args
if(scalar @ARGV != 2) {die "Usage: archive version files\n";}

#See what's in the cwd
opendir CWD, "."  or  die "$!";
@cwdstuff = readdir CWD;

#Search for bakupx dirs and see if there are any files to archive
foreach $i (@cwdstuff) {
	if(-d $i and $i =~ m/^bakup[0-9]+/) { #Don't bakup bakups
		shift @cwdstuff;
    }
    else {
		push @files, $i;
    }
}

#Make a new directory by the version number
$bakup = "bakup" . $ARGV[0];
mkdir($bakup, 0700); 
opendir BAKUP, $bakup  or  die "Can't open $bakup: $!";

#Start bakking up things
foreach $i (@files) {
    $currentname = $bakup . "/" . $i;
        #
	#Troublesome call; directory is successfully made though
	syscall ("cp", $i, $currentname);
}

#cleaning up
closedir BAKUP;

closedir CWD;




>From the land of crashing Forth interpreters
_____________________________________________________________________________
An Thi-Nguyen Le                                          aa
Liberal Arts and Sciences                                {''}--.
http://www.students.uiuc.edu/~anle/HOMEPAGE               oo____'.
================================================================||===========
                                                                j/




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

Date: 19 Sep 1997 21:56:48 -0700
From: Russ Allbery <rra@stanford.edu>
To: An Thi-Nguyen Le <anle@ehsn3.ews.uiuc.edu>
Subject: Re: Copying files
Message-Id: <m390wswpkf.fsf@windlord.Stanford.EDU>

[ Posted and mailed. ]

An Thi-Nguyen Le <anle@ehsn3.ews.uiuc.edu> writes:

> Everything is peachy-keen until line 33, or so perl tells me, with the
> syscall to "cp": "Argument "cp" isn't numeric in syscall at archive line
> 33. Bad system call"

[snip]

> 	#Troublesome call; directory is successfully made though
> 	syscall ("cp", $i, $currentname);

You just have the wrong function for calling other Unix programs.  What
you want is:

        system ('cp', $i, $currentname);

syscall() is for calling system calls, which is more of a low-level kernel
interface than anything else.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Fri, 19 Sep 1997 22:04:09 -0400
From: Benjamin Holzman <bholzman@mail.earthlink.net>
To: Bruno Pagis <bruno_pagis@aur.alcatel.com>
Subject: Re: Hash table reference in regex
Message-Id: <34232F19.78A393D6@mail.earthlink.net>

[posted & mailed]
Bruno Pagis wrote:
> 
> Usage of hash table reference in a regular expression:
> 
> %map = (
>         "UID" => "A",
>          "PID" => "B");
> 
> $msg='<UID>:<PID>';
> $msg =~ s/<(\w+)>/$map{\1}/g;
-------------------------^
You mean: $map{$1}
Backreferences only exist in patterns, not in strings. 

> print "$msg\n";
> 
> I expect A:B but I've got :
> 
> Is it possible to do it in one line ?
> 
> Thanks for helping. BRUNO.

HTH,
Benjamin Holzman


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

Date: Fri, 19 Sep 1997 21:55:22 -0700
From: Kuntal M Daftary <daftary@cisco.com>
Subject: locking files over NFS
Message-Id: <Pine.GSO.3.96.970919214733.22475B-100000@daftary-ultra.cisco.com>

hi people

i have the following situation:

executable "program" is on file system "FS" mounted on machines A and B
the program uses lock files to make sure of mutual exclusion during resource
sharing, which might be writing to a file (in which case file should not be
corrupted during writing). the lock files are also formed on file system "FS"
accessible by both A and B.

now when i run "program" from A and a lock file is formed, the existance of the
lock file may not be immediately reflected on B. so if i almost immediately
start the "program" on B, it may also attempt to write to the data file and
corrupt it.

is there a unix utility to take care of this sitation? does flock take this
problem into account and resolve it? iare there any suggestions that any of u
would like to make as to how to resolve this problem? i m aware of the idea of
waiting some time (like 10 secs) before checking the existance of the lock
file, but that kinda looks kludgy to me and i was hoping for a more elegant
soln.

Kuntal M. Daftary   Cisco Systems Inc 
Ph: 408 527 9789    170 W. Tasman Dr 
daftary@cisco.com   San Jose CA 95134



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

Date: 20 Sep 1997 02:52:33 GMT
From: cowbys@aol.com (COWBYS)
Subject: Perl and form fields
Message-Id: <19970920025200.WAA20417@ladder01.news.aol.com>


Is there a way to use Perl to "pad" input fields from a form once they are
parsed, so for example
If I have a form, and one of its input fields is "Name", with a max input
lenght of 25, and someone enters a name thats only 16 chars long, I can pad
the rest of the field  with 9  zeroes or spaces or something so that its
always 25 chars long regardless of the number of chars entered?

I ask this becuz I am outputting "Name" and other fields to a txt file
which I intend to read later, and I need to know that Name and the other
fileds are always going to be the same length, so I can use seek and read
to pull the values out of this file, always from the same position.

any help, appreciated ... please reply to davef@aasp.net








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

Date: Fri, 19 Sep 1997 22:19:26 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Perl and form fields
Message-Id: <ubfvv5.gt1.ln@localhost>

COWBYS (cowbys@aol.com) wrote:

: Is there a way to use Perl to "pad" input fields from a form once they are
: parsed, so for example
: If I have a form, and one of its input fields is "Name", with a max input
: lenght of 25, and someone enters a name thats only 16 chars long, I can pad
: the rest of the field  with 9  zeroes or spaces or something so that its
: always 25 chars long regardless of the number of chars entered?

: I ask this becuz I am outputting "Name" and other fields to a txt file
: which I intend to read later, and I need to know that Name and the other
: fileds are always going to be the same length, so I can use seek and read
: to pull the values out of this file, always from the same position.


-----------
#!/usr/bin/perl -w

$_ = '1234567890';

printf "==>%16s<==\n", $_; # pad with leading spaces

printf "==>%-16s<==\n", $_; # pad with trailing spaces
-----------


: any help, appreciated ... please reply to davef@aasp.net

Please read the newsgroup where you posted the question.


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: 20 Sep 1997 07:46:11 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: What does this error message mean?
Message-Id: <5vvv04$kqo@agate.berkeley.edu>

In article <Pine.GSO.3.96.970919072738.11506J-100000@julie.teleport.com>,
Tom Phoenix  <rootbeer@teleport.com> wrote:
> On 18 Sep 1997, Joseph Scott Stuart wrote:
> 
> > I get the following error message at the end of my program:
> > 
> > Not a GLOB reference during global destruction (#1)
> > 
> > I do use the glob routine, 
> 
> ...which has nothing to do with the GLOB referred to in the message. :-)
> The GLOB is a typeglob, while the glob() routine is a filename glob -
> totally different animals, even though they have very similar names.
> 
> That error should happen only if something internal to Perl (or a compiled
> module) has a bug in it.

If it is something before 5.004, do not worry, just upgrade.  However,
I have a suspicion that this old-standing bug with IO destruction(*) is
NOT fixed even in 5.004, just hidden.

So if you are running 5.004+, voice again.  Most probably cause is
that you have a __DIE__ handler enabled which does not check for being
inside "generalized eval", so finds a bug in Perl with is hidden by
the fact that error reports are usually disabled during global
destruction. 

Ilya

(*) This bug is double destruction of IO structures.  IO structures
in perl are GLOB which contain a reference to C level IO structure.
Both GLOBs and these C structures have destructors associated with
them, so the destruction happens twice.


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 1053
**************************************

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