[22657] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4878 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 23 09:07:25 2003

Date: Wed, 23 Apr 2003 06:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 23 Apr 2003     Volume: 10 Number: 4878

Today's topics:
    Re: Accesing machines of a network <kasp@epatra.com>
    Re: Accesing machines of a network <tassilo.parseval@rwth-aachen.de>
    Re: Can I die and also write to a log file? <nospamkz15mapson@tellabs.com>
    Re: Can I die and also write to a log file? (Anno Siegel)
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
        file upload not working anymore <andy@mindpilot.ch>
    Re: file upload not working anymore <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: file upload not working anymore <kasp@epatra.com>
    Re: file upload not working anymore <andy@mindpilot.ch>
    Re: file upload not working anymore <noreply@gunnar.cc>
    Re: file upload not working anymore <bart.lateur@pandora.be>
    Re: file upload not working anymore <hyagillot@tesco.net>
    Re: file upload not working anymore <andy@mindpilot.ch>
    Re: file upload not working anymore <andy@mindpilot.ch>
    Re: file upload not working anymore <andy@mindpilot.ch>
    Re: Help: ? $next_one == ${next_one} (Villy Kruse)
    Re: Matching multiple lines <ccsc3618@bigpond.net.au>
    Re: Matching multiple lines (Tad McClellan)
    Re: Q. Does ActivePerl for Windows require Apache to be <bart.lateur@pandora.be>
    Re: Q. Does ActivePerl for Windows require Apache to be (Tad McClellan)
    Re: Read File, write filename? <g4rry_short@zw4llet.com>
    Re: Removal of newline characters <kasp@epatra.com>
    Re: Removal of newline characters <D'oh@a.deer>
    Re: Removal of newline characters <krahnj@acm.org>
    Re: split and substitute ? <kasp@epatra.com>
    Re: split and substitute ? <krahnj@acm.org>
    Re: Tough question for the guru's; Grep Once, Awk Twice (Agrapha)
    Re: Tough question for the guru's; Grep Once, Awk Twice (Tad McClellan)
        use statement <nospam_stigerikson@yahoo.se>
    Re: use statement (Anno Siegel)
    Re: use statement (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 23 Apr 2003 13:19:54 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Accesing machines of a network
Message-Id: <b85gj8$4rn$1@newsreader.mailgate.org>

Thanks for the feedback. I was expecting some more from other people.

> 1. Don't use & to call subroutines unless you are calling
>    them before the sub definition appears and you are not using ()'s.
>    It makes the script look like perl 4.

Doesn't '&' explicity spcifiy that it's a sub routine call, irrespective
whether the sub-routine is defined before or not?

> 2. Don't use a temp file for the net view command, just to reopen it
>    parse it and delete it.  Use a pipe.  (the example I showed you
>    used one).  Using a pipe elimates a file that could get corrupted
>    if more than 1 instance of your script is running at the same time.

Great idea..I will implement it. Even though I will have only one run per
day of script .

> 3. Don't use a global array - (Obviously, you used this because
>    the wanted function for File::Find can not have extra arguments
>    passed to it.  Instead, use a closure. (might be slower though)).
>    You could have also had the wanted function print directly to the file
>    without storing in memory (unless you were planning on sorting them
>    before writing them to file).

I am not doing any sorting operations as of now. So I think its safe to dump
into file/DB right away.

> 3(b). The global array you used you initialized like so:
>      @allFileName = [];
>      In doing this you are setting $allFileName[0] to a
>      newly created array reference.  You have an array within an array.
>      I don't think you meant to do this.

Sorry it was meant to be ().

--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.








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

Date: 23 Apr 2003 09:17:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Accesing machines of a network
Message-Id: <b85lmm$p50$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Kasp:

> Thanks for the feedback. I was expecting some more from other people.
> 
>> 1. Don't use & to call subroutines unless you are calling
>>    them before the sub definition appears and you are not using ()'s.
>>    It makes the script look like perl 4.
> 
> Doesn't '&' explicity spcifiy that it's a sub routine call, irrespective
> whether the sub-routine is defined before or not?

Well, it does force perl to treat the following bareword as a
subroutine. However, it has same side-effects you probably do not want
nor need. Two things: It will have perl ignore the prototype of a
function (if it has one) and secondly it will silently pass @_ to the
subroutine, so:

    function(1, 2, 3);
    
    sub function {
        ...
        &another_func;
    }

    sub another_func {
        print "@_"; # prints "1 2 3"
    }

This behaviour is often used in AUTOLOAD-methods where a new method is
created on the fly and subsequently called with the original parameters
using 'goto &FUNC' (to trick the caller-stack into believing the new
method was called in the first place).

If your main concern is to make it clear that the bareword in question
is a subroutine, simply use parens. In such a case, the function doesn't
have to be pre-declared (or stubbed). Perl does know what you mean in
such a case. So there is no problem at all when you write:

    function_that_is_declared_later();
    ...
    sub function_that_is_declared_later {
        ...
    }
        
>> 2. Don't use a temp file for the net view command, just to reopen it
>>    parse it and delete it.  Use a pipe.  (the example I showed you
>>    used one).  Using a pipe elimates a file that could get corrupted
>>    if more than 1 instance of your script is running at the same time.
> 
> Great idea..I will implement it. Even though I will have only one run per
> day of script .

Using pipe-open has some more benefits. First of all it is much more
efficient to do it that way. In your case, your Perl script needs to
shell-out a process and then open a temporary file that you hand-parse.
This is both more work for you as it is for perl.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 23 Apr 2003 12:38:46 +0100
From: kz15 <nospamkz15mapson@tellabs.com>
Subject: Re: Can I die and also write to a log file?
Message-Id: <3EA67B46.6070502@tellabs.com>

Anno Siegel wrote:
> Sherman Willden <sherman.willden@hp.com> wrote in comp.lang.perl.misc:
> 
>>Can I use die and also write to a log file? I am using perl perl,
>>v5.6.1 built for MSWin32-x86-multi-thread
>>
[snip}
> 
> You can use an "END {}" block to issue a final log message.  "END" is
> executed whenever your program exits, whether normally, through die()
> or even through exit().  The only exceptions are uncaught signals,
> and leaving the program through exec().
> 
> Anno

Anno,

Could this solution also be recommended to the OP?

local $SIG{'__DIE__'} = sub {
    logprint("i'm dying!!!"); # here you can write to the log file
    cleanup();                # close open files, DB handles etc
    exit 1;
};

Greetings,

Zoltan Kandi, M. Sc.



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

Date: 23 Apr 2003 12:23:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Can I die and also write to a log file?
Message-Id: <b860ke$kjl$1@mamenchi.zrz.TU-Berlin.DE>

kz15  <nospamkz15mapson@tellabs.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Sherman Willden <sherman.willden@hp.com> wrote in comp.lang.perl.misc:
> > 
> >>Can I use die and also write to a log file? I am using perl perl,
> >>v5.6.1 built for MSWin32-x86-multi-thread
> >>
> [snip}
> > 
> > You can use an "END {}" block to issue a final log message.  "END" is
> > executed whenever your program exits, whether normally, through die()
> > or even through exit().  The only exceptions are uncaught signals,
> > and leaving the program through exec().
> > 
> > Anno
> 
> Anno,
> 
> Could this solution also be recommended to the OP?
> 
> local $SIG{'__DIE__'} = sub {
>     logprint("i'm dying!!!"); # here you can write to the log file
>     cleanup();                # close open files, DB handles etc
>     exit 1;
> };

I'd use $SIG{ __DIE__} (and $SIG{ __WARN__}) only as a last resort.

For one, it doesn't catch exit(), including the normal end of the
program.  Moreover, a program can use these hooks only once.  If
some other part of the program (possibly a module you are just using)
overwrites your $SIG{ __DIE__}, you have lost.  The same goes the other
way around:  You may be overwriting a $SIG{ __DIE__} that other parts
of the program rely on.  Adding local(), as you did, only restores
the old value after your part of the program is done.

The only way to share $SIG{ foo} is by handler chaining, but that must
be done right, and all involved parties must do it (well, possibly
except one).

Anno


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

Date: 23 Apr 2003 09:05:23 GMT
From: <jari.aalto@poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1051088495@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto <jari.aalto@poboxes.com>

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            XEmacs port is bundled in XEmacs setup.exe available from
            XEmacs site.

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        ftp://ftp.math.ohio-state.edu/pub/users/ilya/perl
        http://www.perl.com/CPAN-local/misc/emacs/cperl-mode/
        <ilya@math.ohio-state.edu>    Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr@ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: Wed, 23 Apr 2003 09:38:33 +0200
From: Andy Meier <andy@mindpilot.ch>
Subject: file upload not working anymore
Message-Id: <BACC0F99.4912%andy@mindpilot.ch>

Hi,

Since over a year I'm using a perl program (using CGI.pm) to upload files on
a server via a browser. And it work perfectly since yesterday. When I try to
upload file now, the files created on server always results with a size of
0KB !?

I did not modify the perl program at all. The Plesk hosting panel says that
there is still plenty of disc space available. I'm also using the same
program on different servers where it still works.

Can anyone point me in the right direction with this?

Andy



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

Date: Wed, 23 Apr 2003 07:43:02 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: file upload not working anymore
Message-Id: <Xns936662BA3A445elhber1lidotechnet@62.89.127.66>

Andy Meier wrote:


[...]


> I did not modify the perl program at all. The Plesk hosting panel says
> that there is still plenty of disc space available. I'm also using the
> same program on different servers where it still works.


In that case what makes you think this is a Perl question?


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Wed, 23 Apr 2003 13:22:05 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: file upload not working anymore
Message-Id: <b85hac$66k$1@newsreader.mailgate.org>

If you could provide the script, it might help in doing some analysis as to
why the problem is occurring

--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Wed, 23 Apr 2003 10:14:13 +0200
From: Andy Meier <andy@mindpilot.ch>
Subject: Re: file upload not working anymore
Message-Id: <BACC17F5.4916%andy@mindpilot.ch>


>> I did not modify the perl program at all. The Plesk hosting panel says
>> that there is still plenty of disc space available. I'm also using the
>> same program on different servers where it still works.
> 
> 
> In that case what makes you think this is a Perl question?

You are right. It looks like this is a problem on the server side. But since
my provider could not give me an answer in the first place I hoped that some
other perl programmer might have experienced the same problem in the past
and know why this happens. I'll expand my research on the server group as
well...

Cheers
Andy



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

Date: Wed, 23 Apr 2003 10:39:09 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: file upload not working anymore
Message-Id: <b85ji7$6bvqe$1@ID-184292.news.dfncis.de>

Andy Meier wrote:
> Since over a year I'm using a perl program (using CGI.pm) to upload
> files on a server via a browser. And it work perfectly since
> yesterday. When I try to upload file now, the files created on
> server always results with a size of 0KB !?
> 
> I did not modify the perl program at all.

That makes me think of a change in file ownership, and/or a change in
the user that CGI scripts are run as. Providers of shared web hosting
accounts occationally make such changes without informing their
customers properly.

This is just a guess, of course, but the first thing I would try is to
set the file permission of the directory to which you want to upload
files to 777, and see if that makes a difference.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 23 Apr 2003 10:23:08 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: file upload not working anymore
Message-Id: <kcqcavgk6a26ik1c8jb0j7cpgfl59vjf9e@4ax.com>

Andy Meier wrote:

>Since over a year I'm using a perl program (using CGI.pm) to upload files on
>a server via a browser. And it work perfectly since yesterday. When I try to
>upload file now, the files created on server always results with a size of
>0KB !?
>
>I did not modify the perl program at all.

Did you change browser?

-- 
	Bart.


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

Date: Wed, 23 Apr 2003 11:21:37 +0000 (UTC)
From: "W K" <hyagillot@tesco.net>
Subject: Re: file upload not working anymore
Message-Id: <b85t01$bv0$1@sparta.btinternet.com>


"Andy Meier" <andy@mindpilot.ch> wrote in message
news:BACC17F5.4916%andy@mindpilot.ch...
>
> >> I did not modify the perl program at all. The Plesk hosting panel says
> >> that there is still plenty of disc space available. I'm also using the
> >> same program on different servers where it still works.
> >
> >
> > In that case what makes you think this is a Perl question?

It may be off topic but chances are we've made the mistake.

> You are right. It looks like this is a problem on the server side. But
since
> my provider could not give me an answer in the first place I hoped that
some
> other perl programmer might have experienced the same problem in the past
> and know why this happens. I'll expand my research on the server group as
> well...

I'd bet 10:1 that its the HTML in the web page sending the data.

You haven't mentioned whether you have the "multipart" etc.etc. enctype set.




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

Date: Wed, 23 Apr 2003 13:41:01 +0200
From: Andy Meier <andy@mindpilot.ch>
Subject: Re: file upload not working anymore
Message-Id: <BACC4677.4C9F%andy@mindpilot.ch>

>> Since over a year I'm using a perl program (using CGI.pm) to upload files on
>> a server via a browser. And it work perfectly since yesterday. When I try to
>> upload file now, the files created on server always results with a size of
>> 0KB !?
>> 
>> I did not modify the perl program at all.
> 
> Did you change browser?

I tested on different browsers on Windows98 and Mac. It worked with none of
them. I even switched from my ADSL connection to a regular modem dial-up to
make shure that there's no connection problem. No luck either!

Andy



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

Date: Wed, 23 Apr 2003 13:41:01 +0200
From: Andy Meier <andy@mindpilot.ch>
Subject: Re: file upload not working anymore
Message-Id: <BACC485A.4CA0%andy@mindpilot.ch>

>>>> I did not modify the perl program at all. The Plesk hosting panel says
>>>> that there is still plenty of disc space available. I'm also using the
>>>> same program on different servers where it still works.
>>> 
>>> 
>>> In that case what makes you think this is a Perl question?
> 
> It may be off topic but chances are we've made the mistake.
> 
>> You are right. It looks like this is a problem on the server side. But
> since
>> my provider could not give me an answer in the first place I hoped that
> some
>> other perl programmer might have experienced the same problem in the past
>> and know why this happens. I'll expand my research on the server group as
>> well...


> I'd bet 10:1 that its the HTML in the web page sending the data.
> 
> You haven't mentioned whether you have the "multipart" etc.etc. enctype set.

Hm, the HTML page looks like this. It's not working with a bare bones
version of the form or forms/scripts from other programmers either. I also
tested on different browsers/plattforms and connections: it does not work
anymore.

What's bothering me most is, that it always worked until now!

Andy


----

<html>

 <head>
  <title>send new file to server</title>
 </head>
 <body bgcolor="#FFFFFF" text="#000000" link="#FF9900" alink="#FF0000"
vlink="#999999" leftmargin="0" marginwidth="0" topmargin="0"
marginheight="0">
  <center>
   <table border="0" cellpadding="2" cellspacing="0" width="100%"
bgcolor="#006699">
    <tr>
     <td></td>
     <td><strong><font color="#ffffff">Upload</font></strong></td>
    </tr>
   </table>
   <p>&nbsp;</p>
   
   <form name="UploadForm" enctype="multipart/form-data"
action="/cgi-bin/upload/imgUp2.pl" method="POST">

    <table border="0" cellpadding="7" cellspacing="0">
     <tr>
      <td><font size="5"><strong>1.</strong></font></td>
      <td>Datei ausw&auml;hlen... (max. 200 kb)</td>
     </tr>
     <tr>
      <td></td>
      <td><input type="FILE" name="file_to_upload" size="28"></td>
     </tr>
     <tr>
      <td><font size="5"><strong>2.</strong></font></td>
      <td><input type="submit" value="senden"></td>
     </tr>
    </table>
    <p>
    
   </form>
  </center>
 </body>

</html>



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

Date: Wed, 23 Apr 2003 14:05:35 +0200
From: Andy Meier <andy@mindpilot.ch>
Subject: Re: file upload not working anymore
Message-Id: <BACC4E2F.4CA5%andy@mindpilot.ch>


>>> I did not modify the perl program at all. The Plesk hosting panel says
>>> that there is still plenty of disc space available. I'm also using the
>>> same program on different servers where it still works.
>> 
>> 
>> In that case what makes you think this is a Perl question?
> 
> You are right. It looks like this is a problem on the server side. But since
> my provider could not give me an answer in the first place I hoped that some
> other perl programmer might have experienced the same problem in the past
> and know why this happens. I'll expand my research on the server group as
> well...
> 
> Cheers
> Andy

The Perl part of my problem looks like this but a I mentioned I "fear" that
the script is O.K.

Andy

----

#!/usr/bin/perl -w

use strict;
use CGI;

my $cgi = new CGI; # new Object

#--- get file data
my $file = $cgi->param("file_to_upload");

#--- save directory
my $dir = "$ENV{'DOCUMENT_ROOT'}";

#--- full file name path
my $fname = "$dir/$file";

#--- opening the file
open(DAT,'>'.$fname) || &showError("Error processing file: $!");

#--- switching to binary mode
binmode $file;
binmode DAT;

my $buffer = "";

while(read($file,$buffer,$ENV{CONTENT_LENGTH})) {
  print DAT $buffer;
}
close DAT;

#--- Result page
print $cgi->header(-type => 'text/html');
print <<HTML;

<html>
<head>
<title>Fileupload</title>
</head>
<body bgcolor="#FFFFFF">
<h2>File uploaded</h2>

<p>The file &quot; $file &quot; has been saved on the server.<br>
$ENV{CONTENT_LENGTH}
</p>
</body>
</html>
HTML

##########

sub showError{

    my $message = shift(@_);

print <<HTML;
<html>
<head><title>Error</title></head>
<body bgcolor="#FFFFFF">
<h2>Error</h2>
<p>$message</p>
</body>
</html>
HTML

}



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

Date: 23 Apr 2003 12:59:49 GMT
From: vek@station02.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Help: ? $next_one == ${next_one}
Message-Id: <slrnbad3i5.1ng.vek@station02.ohout.pharmapartners.nl>

On 22 Apr 2003 14:09:12 +0100,
    Brian McCauley <nobull@mail.com> wrote:


>Bob Walton <bwalton@rochester.rr.com> writes:
>
>> ... trying to interpolate the variable in a string where the variable name
>> is followed by an alphanumeric character, like "abc${next_one}def" for
>> example.  That is mostly why the construct is available in Perl -- if
>> it weren't, there would be no way to interpolate a variable name
>> followed immediately by an alphanumeric character, as the compiler
>> would have no way of knowing where the variable name is supposed to
>> stop and the literal text start.
>
>Well, at some level that's true.  But looking at it another way, if
>this construct did not exist then there would have to be another way.
>I personally think this construct is ugly and think Perl would have
>been a nicer place without it.
>
>We could perfectly well have got around the interpolation problem by
>using an escape seqence that interpolates as a null string.  Indeed
>you can use \E for this purpose but it has other effects too so a
>separate null escape would have been preferable.
>
> "abc$next_one\Edef" 
>


"abc" . $next_one . "def"

is also a posible way; which may result in the same compiled bytecode.



Villy


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

Date: Wed, 23 Apr 2003 08:01:55 GMT
From: "rjh" <ccsc3618@bigpond.net.au>
Subject: Re: Matching multiple lines
Message-Id: <TLrpa.7771$8K2.69742@news-server.bigpond.net.au>

After thinking about it, a solution came about as per below.

&OpenFile("-d");
foreach $filename (readdir(DIRHANDLE)){
            if(-d $filename) {;next;}
            $/ = $separator;
            &OpenFile("-g", $filename);
            while (<FILEHANDLE>) {
                if(m/^(\d.*)/){$timestamp = $+;}
                if(/\w.*/s) { $w = $_;}
                if($_ =~ /$line/){ print "$timestamp, $w"; }
            }close FILEHANDLE;


I have mentioned a couple of sub functions here but you should be able to
work out what they do
from their arguments.


Thanks
rjh.

"rjh" <ccsc3618@bigpond.net.au> wrote in message
news:Pqppa.7612$8K2.67658@news-server.bigpond.net.au...
> Hi,
> say my file has the form
>
> 2003/12/02 hh:mm --
> ---------------------
> this is a piece
> of multi line
> text
> ---------------------
> 2003/12/01 hh:mm --
> ---------------------
> this is a single line of text
> ---------------------
> 2003/12/01 hh:mm --
> ---------------------
> this is another multiple
> line of text
> where i just write stuff
> ---------------------
>
> Setting $/ to "----------------" works for matching multiple lines, but
how
> can i match the timestamp above the ---------------.
> Is there a special var for that ? Does setting $/ to "------------" mean
> that the timestamp will be missed altogether.
> Should i try and match the timestamp and then set $/ to = "--------------"
> once it is matched, then set $/ back to the normal RECORD separator before
> matching the next timestamp.
> ie
>
> while (<>) {
>     $timestamp = m/\d{4,}.*/;   # etc etc
>     $/ = "------------";
>     if(/\w.*/s) { $w = $_;}
>     if($_ =~ /$line/){ print "$timestamp, $w\n";
> }
>
>
>
> Any thought, Recomendations most welcome.
>
> Thanks.
> rjh.
>
>
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnba74av.m4q.tadmc@magna.augustmail.com...
> > rjh <ccsc3618@bigpond.net.au> wrote:
> >
> > > Im trying to search the file for the ---------- delimiter and then
read
> the
> > > data into an array,  then search the
> > > array for a match and then print out the array.
> >
> >
> > Look up the  $/  variable in perlvar.pod.
> >
> >
> > --
> >     Tad McClellan                          SGML consulting
> >     tadmc@augustmail.com                   Perl programming
> >     Fort Worth, Texas
>
>




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

Date: Wed, 23 Apr 2003 07:20:25 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Matching multiple lines
Message-Id: <slrnbad189.t97.tadmc@magna.augustmail.com>

rjh <ccsc3618@bigpond.net.au> wrote:


> Setting $/ to "----------------" works for matching multiple lines, but how
> can i match the timestamp above the ---------------.
> Is there a special var for that ? Does setting $/ to "------------" mean
> that the timestamp will be missed altogether.


No, it means that you will read *two* physical records for
each logical record. That is, 1st read gets the timestamp,
2nd read gets the data.

This is because you've used the same delimiter for both parts. If you
control the format of the data file, change the "interior" delimiter
to something else if you want one-read-per-record. Something like:

   2003/12/02 hh:mm --
   -----
   this is a piece
   of multi line
   text
   ---------------------


>     $timestamp = m/\d{4,}.*/;   # etc etc


That accomplishes nothing. You should never have a "bare" m// operator
like that.

The only useful info you get from a m// is the true (match succeeded)
or false (match failed) that it returns, so the m// should always
be in a condition that tests for the success/failure.

Also, that could match the wrong thing with data like:

   2003/12/02 hh:mm --
   ---------------------
   the house
   costs $50000
   ---------------------

since the "5000" in the 2nd record will match that pattern.


> Any thought, 

-------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;

local $/ = "---------------------\n";
my $timestamp;
while ( <DATA> ) {
   if ( m#^(\d{4}/\d\d/\d\d)# ) {  # timestamp record
      $timestamp = $1;
   }
   else {                          # data record
      print "$timestamp, $_\n";
   }
}



__DATA__
2003/12/02 hh:mm --
---------------------
this is a piece
of multi line
text
---------------------
2003/12/01 hh:mm --
---------------------
this is a single line of text
---------------------
2003/12/01 hh:mm --
---------------------
this is another multiple
line of text
where i just write stuff
---------------------
-------------------------------------------


> Recomendations most welcome.


Please do not top-post again.


[snip TOFU]

-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 23 Apr 2003 11:13:42 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Q. Does ActivePerl for Windows require Apache to be installed ?
Message-Id: <f6tcav4uilbh9la8devu7gbca5tkep8opb@4ax.com>

Helgi Briem wrote:

>>>> Does ActivePerl for Windows require Apache to be installed ?
>>>
>>>No, it doesn't.
>>
>>Thank you very much for your help. I sure wish that the ActiveState
>>site mentioned that little fact which has had me confused all day.
>
>Why on earth should Activestate mention that??

What they do mention, is that you need a recent version of Internet
Explorer. AFAIK, that isn't true.

-- 
	Bart.


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

Date: Wed, 23 Apr 2003 07:51:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Q. Does ActivePerl for Windows require Apache to be installed ?
Message-Id: <slrnbad31q.t97.tadmc@magna.augustmail.com>

Jim <harley.davidsno@mailcity.com> wrote:

> I was only able to run Perl
> scripts in DOS.


That is the best way to learn Perl programming (if "DOS" means "command line").


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 23 Apr 2003 13:44:25 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: Read File, write filename?
Message-Id: <b861ug$sbt$1$8300dec7@news.demon.co.uk>

entropy123 wrote:

> Hey all,
> 
> I am a major Perl newbie working through 'Learning Perl' and I can't
> figure out how to do this:
> 
> Have perl read the contents of a file with a *.txt and take the * part
> of the file and write it to the first line of the new file.
> 
> Any suggestions?
> Thanks,
> entropy
 Hmmm ... your question's not brilliantly phrased.
1. Where are you getting the filename from in the first place?
2. I take it it's the fileNAME you want to write to the file?
3. What new file??

Assuming you're being given a new filename to create, you should have
something like this :

#!/usr/bin/perl -w

# Assume the new filename is defined within the script; define it now.
my $filename = "rhubarb.txt";

# Try to open/create the file for writing; end the script and report if 
# there are errors.
open NEWFILE, ">$filename" or die "Can't open $filename: $!\n";
# Remove ".txt" from the filename
$filename =~ s/\.txt//;
# Print the filename to the new file
print NEWFILE "$filename\n";
# Close the file.
close NEWFILE;

HTH,

Garry




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

Date: Wed, 23 Apr 2003 13:38:30 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: Removal of newline characters
Message-Id: <b85i78$7p7$1@newsreader.mailgate.org>

In your code...

>   while (my $value = ($searchresult =~ m/  /)){       # While double
> spaces exist in $string
>           $searchresult =~ s/  / /;                     # Remove and
> replace with single spaces
>                  }

You are first checking if a double space exists and then calling replace.
This is not required.
Why don't you call replace directly without checking? as I see you are not
doing any other processing for a double space scenario. This will improve
the speed slightly.
--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.





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

Date: Wed, 23 Apr 2003 21:41:50 +1000
From: D'oh <D'oh@a.deer>
Subject: Re: Removal of newline characters
Message-Id: <3EA67BFE.39B0646@a.deer>

Stephen Adam wrote:
> 
>           $searchresult =~ s/\n/ /;   # !! The bit that don't work!!

replace with

            chomp($searchresult);


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

Date: Wed, 23 Apr 2003 12:58:23 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Removal of newline characters
Message-Id: <3EA68DDA.56056ED5@acm.org>

Stephen Adam wrote:
> 
> Very simple one here, I need to remove the new line characters from a
> scalar before I more it into an array. I'm trying to use replace
> feature ($searchresult =~ s/\n/ /;) but it don't seem to work. Sure
> i'm just being silly.
> 
> The program downloads a search page from from google, places it in a
> scalar, then removes all double spaces. After that it should remove
> all of the new line chars. Then it places the result in the array. I'm
> still quite new to Perl so if you could explain whats going wrong in
> detail that would be great + if there are any better ways of doing
> what already works then please let me know.
> 
> #!C:\perl\perl.exe
> 
> use warnings;
> use strict;
> use vars qw($PARSE);
> use LWP::Simple qw/$ua get/;
> our @googlearray; # Here we hold the result of the search on google
> 
>         &searchweb;
> 
> #pre  - true
> #post - yahoo and google array are filled and cleaned
> 
> sub searchweb{
> 
> my $searchresult;         # This is a temp variable to hold web result
> 
> print "Please enter your search criteria \n";
>         my $search = <STDIN>;

Getting your input from STDIN means that there will be a newline at the
end of the string.

          chomp( my $search = <STDIN> );


> $ua  = LWP::UserAgent->new(env_proxy => 1, agent => 'a searching we
> will go');
> $searchresult = get "http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=$search";
> 
>   if ($searchresult){
>       $searchresult =~ tr/[A-Z]/[a-z]/;     # Place result in lower case
                                ^   ^ ^   ^
Why are you replacing a '[' with a '[' and a ']' with a ']'?  Why not
use Perl's lc() function?

        $searchresult = lc $searchresult;


>       $searchresult =~ s/\n/ /;   # !! The bit that don't work!!

That is replacing the FIRST newline with a space, not all the newlines.

        $searchresult =~ s/\n/ /g;


>       while (my $value = ($searchresult =~ m/  /)){       # While double
> spaces exist in $string
>           $searchresult =~ s/  / /;                     # Remove and
> replace with single spaces
>           }

There is no need for the while loop:

        $searchresult =~ s/  / /g;


>           @googlearray = (split//, $searchresult);
                            ^^^^^^^
That splits the contents of $searchresult into single characters, are
you sure that is what you want?


>           } else {
>           print "ERROR - unable to download google search - please
> check internet connection.";}
> 
> foreach my $i (@googlearray){
> print "$i";
        ^  ^
The quotes are not doing anything useful there.

print $i;

However, if you just want to print the array there is no need for a
loop:

print @googlearray;


> }
> 
> # Save result to file for error checking
> $PARSE = ">./parsefile.dat";
>  open(PARSE) or die ("Can't open the file");

Ick, why use that obscure form of open?  You should include the $!
variable in the error message so you know WHY it failed.


>  print PARSE "$searchresult";
               ^             ^
The quotes are not doing anything useful there.

  print PARSE $searchresult;


>  close $PARSE;
> 
>  }
> 
> exit(0);


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 23 Apr 2003 13:32:09 +0530
From: "Kasp" <kasp@epatra.com>
Subject: Re: split and substitute ?
Message-Id: <b85hae$66k$2@newsreader.mailgate.org>

> 0001 0002 0003 0003A0004 0005
This data does not have a common record separator - unlike your first case.
So you might want to process this data so as to have a common separator
first.and then use split as Bernard pointed out.

Optionally, if you agree to lose the A - then you can split on whitespace or
alphabets as in
split(/\s|\w/,  $pages{$uhi});

--
"Accept that some days you are the pigeon and some days the statue."
"A pat on the back is only a few inches from a kick in the butt." - Dilbert.




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

Date: Wed, 23 Apr 2003 13:03:41 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: split and substitute ?
Message-Id: <3EA68F1C.101BD2A7@acm.org>

Cao Tran wrote:
> 
> Here is my data from a hash key ($pages{$uhi}):
> 
> :0001:0002:0003:0004:0005
> 
> I want to split and put in an array
> 
> @Page = split (/:/, $pages{$uhi});
> 
> foreach (@Pages){print "\n"}
> 
> Output in @Page:
> 0001
> 0002
> 0003
> 0004
> 0005
> 
> which work fine, but I have another database that has this kind of
> data:
> 
> 0001 0002 0003 0003A0004 0005
> 
> I want to add to @Page and have output similiar to these:
> 0001
> 0002
> 0003
> 0003A
> 0004
> 0005
> 
> How do I write code to cover both case?  I don't know much of split
> function, could someone help me with this.  One other note: I can't
> write to the database.


@Page = $pages{$uhi} =~ /[[:alnum:]]{4,5}/g;


John
-- 
use Perl;
program
fulfillment


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

Date: 23 Apr 2003 03:02:44 -0700
From: brian@box201.com (Agrapha)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <11aabb15.0304230202.5cd1866d@posting.google.com>

Uri Guttman <uri@stemsystems.com> wrote in message news:<x7adehvnvn.fsf@mail.sysarch.com>...
> this is a perl discussion group and not a rewrite my shell script in
> perl for me group.
> 
> even if you did get someone to rewrite it, you don't know any perl so
> how could you maintain it? will you regularly repost it here so we can
> add features and fix things when the formats change?
> 
> the amount of perl you need is minimal so why don't you learn it?
> 
> uri

whew, 71 words and not 1 bit of code....impressive. 
I am learning perl otherwise I would post this in a PHP discussion
group. But I will be honest I am on a deadline here. I can use some
help if I can only get complaints about posting then I shall look
elsewhere.

My knowledge of perl is so far limited. if you care to have updated
posts I am not opposed to that. The script will need to be portable.
It is for emergencies only. Normally there is a much more complicated
program which pulls this data for us. The other night that program
broke. So I whipped up the shell script in a hurry.

My script is functional but not professional, not efficient. I'm not
pleased with how much cpu it took to run it. My dataset can have as
many as 200,000 rows in it. Out of that I am really only concerned
with 3 columns. $4, $5,and $8 of those three $5 is (in perlesque
language) just a $ARGV. I use that in my script as $1 to find all the
rows which match a value I pass to the scipt on the command line.

The key question I have is if I have a dataset that big should I load
a @var with every value after the initial grep and how can I rescan
the data to give me the other views I need without touching the drive
again. Just a push to the standard output.


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

Date: Wed, 23 Apr 2003 07:59:40 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Tough question for the guru's; Grep Once, Awk Twice (or more)
Message-Id: <slrnbad3hs.t97.tadmc@magna.augustmail.com>

Agrapha <brian@box201.com> wrote:
> Uri Guttman <uri@stemsystems.com> wrote in message news:<x7adehvnvn.fsf@mail.sysarch.com>...

>> this is a perl discussion group and not a rewrite my shell script in
>> perl for me group.


> I am on a deadline here. 


That is your concern, not our concern.


> if I can only get complaints about posting then I shall look
> elsewhere.


Thank you.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 23 Apr 2003 13:47:13 +0200
From: stig <nospam_stigerikson@yahoo.se>
Subject: use statement
Message-Id: <b85ulv$gu9$1@oden.abc.se>

hello
if i want to use the use statement with a file not in the current directory
and not in the directories specified in the standard paths, how should i
do?

example:
use ../otherdir/ModuleName;
use '../otherdir/ModuleName';
use "../otherdir/ModuleName";

non of the above work. i also tried with absolute paths, and adding the .pm
extension in the names.

help much appreciated
stig


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

Date: 23 Apr 2003 12:27:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: use statement
Message-Id: <b860r7$kjl$2@mamenchi.zrz.TU-Berlin.DE>

stig  <nospam_stigerikson@yahoo.se> wrote in comp.lang.perl.misc:
> hello
> if i want to use the use statement with a file not in the current directory
> and not in the directories specified in the standard paths, how should i
> do?
> 
> example:
> use ../otherdir/ModuleName;
> use '../otherdir/ModuleName';
> use "../otherdir/ModuleName";
> 
> non of the above work. i also tried with absolute paths, and adding the .pm
> extension in the names.

    perldoc lib

Anno


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

Date: Wed, 23 Apr 2003 08:41:52 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: use statement
Message-Id: <slrnbad610.uq7.tadmc@magna.augustmail.com>

stig <nospam_stigerikson@yahoo.se> wrote:

> if i want to use the use statement with a file not in the current directory
> and not in the directories specified in the standard paths, how should i
> do?
> 
> example:
> use ../otherdir/ModuleName;


   use lib '../otherdir';
   use ModuleName;


Do see the documentation for the "lib" pragma:

   perldoc lib


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 4878
***************************************


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