[22335] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4556 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 12 11:05:55 2003

Date: Wed, 12 Feb 2003 08:05:10 -0800 (PST)
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, 12 Feb 2003     Volume: 10 Number: 4556

Today's topics:
        Accessing files in html folder from cgi script (Craig)
        amateur needs pattern matching example (Mooky Mooksgill)
    Re: amateur needs pattern matching example <jurgenex@hotmail.com>
        Analyzing Columns of Data (brice)
    Re: Analyzing Columns of Data ctcgag@hotmail.com
    Re: Analyzing Columns of Data <pinyaj@rpi.edu>
    Re: building hash <bigj@kamelfreund.de>
    Re: building hash <bigj@kamelfreund.de>
    Re: createing a daemon <ryan@dctnet.net>
        Custom HTTP 404 Error Redirect  <paanwa@hotmail.com>
    Re: Custom HTTP 404 Error Redirect (Anno Siegel)
    Re: Custom HTTP 404 Error Redirect <flavell@mail.cern.ch>
    Re: extracting JS links with Perl <Wolfgang_.fischer@freenet.de>
    Re: Fork multiple children, read from their pipes ctcgag@hotmail.com
        grep with line number ? <kamran@norsar.no>
    Re: grep with line number ? (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
    Re: grep with line number ? <kamran@norsar.no>
    Re: grep with line number ? (Anno Siegel)
    Re: grep with line number ? (Anno Siegel)
    Re: grep with line number ? (Helgi Briem)
    Re: Insecure Filehandle Dependencies <j.j.konkle-parker@larc.nasa.gov>
        Minimalist Perl Interpreter for Windows 98 and XP? (Goh, Yong Kwang)
    Re: Minimalist Perl Interpreter for Windows 98 and XP? <bart.lateur@pandora.be>
        mod_perl, subdomains, and cookies (Toni Ellison)
        PERL JAYCAR IO Parallel <andrew.rich@bigpond.com>
    Re: Perl script to create new user in Linux. <josef.moellers@fujitsu-siemens.com>
    Re: Perl script to create new user in Linux. <scare.crow@oz.land>
    Re: Perl script to create new user in Linux. (W. Citoan)
    Re: Perl script to create new user in Linux. <kjetil.klove@nrk.no>
    Re: print <<HERE; (Tad McClellan)
    Re: print <<HERE; <shanem@nospam.ll.mit.edu>
        puzzling operator priorities <chang0@adelphia.net>
    Re: Re Installing modules from CPAN <brian.smart@blueyonder.co.uk>
    Re: Re Installing modules from CPAN (Randy Kobes)
    Re: Request help with this script (Tad McClellan)
    Re: strict and warnings <tassilo.parseval@post.rwth-aachen.de>
        Subs in external files? <j.j.konkle-parker@larc.nasa.gov>
    Re: Subs in external files? <Wolfgang_.fischer@freenet.de>
    Re: Subs in external files? <j.j.konkle-parker@larc.nasa.gov>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Feb 2003 05:04:01 -0800
From: craigdessoy@hotmail.com (Craig)
Subject: Accessing files in html folder from cgi script
Message-Id: <9c4d8212.0302120504.4599df2a@posting.google.com>

hi all
i am trying to send an email from a cgi script (in the cgi-bin), which
attaches a csv file located in the html folder. for this i am using
/mainwebsite_html/file.csv . when i run this script from the browser
or command line i get a software error: /mainwebsite_html/file.csv not
readable. i tried an absolute address and got the same error.
permissions are set at 755.
does anyone have any suggestions?
thanks~
craig


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

Date: 12 Feb 2003 05:40:51 -0800
From: starman7@hotmail.com (Mooky Mooksgill)
Subject: amateur needs pattern matching example
Message-Id: <8c02f0c6.0302120540.7cc0b286@posting.google.com>

I'd like to parse certain values out of an HTML file and into a new
file that will be used as an SSI.

here's one line of foo.html - 

<font face="verdana" size="1" color="#333366"><b>8:25
AM</b>&nbsp;</font></td>

I'd like just the '8:25 AM'

and put in to a file bar.inc as:

<td class=time>8:25 AM</td>

I will repeat with date, etc. all values i want appear between certain
(matchable) HTML tags.

examples are appreciated,

many thanks!


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

Date: Wed, 12 Feb 2003 15:22:48 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: amateur needs pattern matching example
Message-Id: <cFt2a.6503$SB2.488@nwrddc03.gnilink.net>

Mooky Mooksgill wrote:
> I'd like to parse certain values out of an HTML file [...]

Don't say another word but read the FAQ "How do I remove HTML from a
string?".
In short: use an HTML parser to parse HTML, e.g. HTML::Parser.

jue




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

Date: 12 Feb 2003 06:50:05 -0800
From: bricemason@hotmail.com (brice)
Subject: Analyzing Columns of Data
Message-Id: <50404b7a.0302120650.48453796@posting.google.com>

Hello,

I have a comma-separated value file of the following format:

first_value,second_value,third_value
1,2,3
10,20,30
32,11,52

and so on...

I want to grab each column of data as it's own array. In other words,
I want to have the first array be:

array1[0] = "first_value"
array1[1] = "1"
array1[2] = "10
array1[3] = "32"

My script has to account for varying numbers of columns as I won't
always have three columns to work with. Any ideas on this? I just need
a little nudge on this to get going.

Thanks in advance,

brice


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

Date: 12 Feb 2003 14:56:06 GMT
From: ctcgag@hotmail.com
Subject: Re: Analyzing Columns of Data
Message-Id: <20030212095606.852$Rf@newsreader.com>

bricemason@hotmail.com (brice) wrote:
> Hello,
>
> I have a comma-separated value file of the following format:
>
> first_value,second_value,third_value
> 1,2,3
> 10,20,30
> 32,11,52
>
> and so on...
>
> I want to grab each column of data as it's own array.

Data::Table

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Wed, 12 Feb 2003 10:00:17 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: brice <bricemason@hotmail.com>
Subject: Re: Analyzing Columns of Data
Message-Id: <Pine.SGI.3.96.1030212095444.51853A-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 12 Feb 2003, brice wrote:

>I have a comma-separated value file of the following format:
>
>first_value,second_value,third_value
>1,2,3
>10,20,30
>32,11,52

I recommend using one of the CPAN modules (such as Text::CSV, or better
yet Text::CSV_XS) to parse each line into its values.  However, if you're
*SURE* there will be no need to parse embedded commas in quotes, and there
will be no other anomolies, then a simple

  chomp;
  my @fields = split /,/;

should do the trick to get the values on a line into an array.

>I want to grab each column of data as it's own array. In other words,
>I want to have the first array be:
>
>array1[0] = "first_value"
>array1[1] = "1"
>array1[2] = "10
>array1[3] = "32"

For this you need an array of array( reference)s.  Assuming you'll have
some function parse() that splits the string up into its individual values
you can do this:

  my @data;

  while (<INPUT>) {
    chomp;
    my @fields = parse($_);  # sub parse { split /,/, shift }, for example
    for (0 .. $#fields) {
      push @{ $data[$_] }, $fields[$_];
    }
  }

If you don't understand references, or the syntax I've used, you need to
read some Perl documentation:

perldoc perlreftut
perldoc perlref

for a start.

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Wed, 12 Feb 2003 12:42:04 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: building hash
Message-Id: <pan.2003.02.12.11.19.25.803134@kamelfreund.de>

On Tue, 11 Feb 2003 19:31:17 +0000, Tassilo v. Parseval wrote:

>> I'm afraid my explanation is confusing. But the main idea is simply to
>> compress not all together, but in seperated blocks that can be
>> distinguished by e.g. the hash value. That would have also the
>> advantage that it could be used efficient in RAM as also on DISK.
> 
> I think I did understand it roughly. The above would make a lot of sense
> if Perl had a more sophisticated tie() interface. It is particularly
> incomplete for scalars, I think. Whenever you do
> 
>     $tied_scalar .= "some string";
> 
> this results in a FETCH and STORE operation. But instead, an APPEND is
> needed here (where you could use the above block structure to append to
> the last block only), otherwise you temporarily need the amount of
> memory required for the uncompressed data. Also, a lot of string
> operators should be tieable. A tied interface really should have a
> SUBSTR(), CHOP(), CHOMP() etc. method to make tying scalars more useful
> that it is right now.
> 
>> Looking forward to such a module,
> 
> The more I think about it, the more I feel that such a thing is
> currently not possible via tie(). :-( I see a slight chance for arrays
> and hashes however, since they offer a more sophisticated interface.

Erm, yes, scalars will bring real problems.

But I believe, users have often large data in hashes and sometimes in
arrays. Really large scalars are very seldom (especially as they don't
produce extra overhead) and can in many cases easily avoided (by choosing
a proper data structure). So, what belongs to me, I would already bless
you for a data compressed hash or array module :-)


Greetings,
Janek

PS: Well, on the other hand I believe, we can simulate such a fine grained
tie - interface for scalars with object methods. .= (and other operations
like magical ++) can be overloaded, substr(...), chop(), chomp(...) could
be overwritten (I hope, I'm not sure) .....


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

Date: Wed, 12 Feb 2003 12:42:04 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: building hash
Message-Id: <pan.2003.02.12.11.20.26.634320@kamelfreund.de>

On Tue, 11 Feb 2003 22:45:19 +0000, Sharon Grant wrote:

>>Another is to use the quick Berkeley DB via the Perl module
>>Tie::DB_File
> 
> What does that do?
> 
> The DB_File module comes with Perl and already has
> an interface for tie-ing a Berkeley/DB file to a
> Perl hash

I had just a typo :-(
I meant DB_File.


Greetings,
Janek


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

Date: Wed, 12 Feb 2003 08:55:27 -0500
From: ryan <ryan@dctnet.net>
Subject: Re: createing a daemon
Message-Id: <pan.2003.02.12.08.55.24.293956.3974@dctnet.net>

On Tue, 11 Feb 2003 15:24:51 -0500, Abigail wrote:

> ryan (ryan@dctnet.net) wrote on MMMCDLI September MCMXCIII in
> <URL:news:pan.2003.02.11.13.19.09.119902.20427@dctnet.net>: --  Hi, --  
> I was wondering if anyone can point me to some information about --
>  creating a daemon with perl.  I want it to run from the init.d and be
> --  able to use the start|stop|restart options.  It will just proccess a
> --  queue file, so it won't be all that complex. Any help would be
> greatly --  appreciated.  I don't really want to have it run as a cron
> job, as it --  will not be as robust as I would like it to be.  Thanks
> again.
> 
> 
> perlipc would be your first source of information. After that, I
> strongly suggest "Advanced Programming in the UNIX Environment".
> 
> Often, daemons started from init.d leave a "pid file" behind, storing
> the PID of the daemon. This can be used to avoid having multiple
> instances of the same daemon running, but also when shutting down.
> Typically, a daemon is shut down by sending it a signal. The restart
> option is sometimes implemented by sending the daemon a signal (SIGHUP
> for instance, or SIGUSR1), and sometimes by just stopping and starting
> it.
> 
> Nothing of the above is typical Perl, you'd do similar steps for
> non-Perl daemons.
> 
> 
> Abigail


Thanks all for the pointers! I will explore this further, because of time
issues this may have to be put off until later but I definely think this
is the way to go with my current project but again it may have to wait
for now. Thanks again

Ryan


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

Date: Wed, 12 Feb 2003 07:52:42 -0500
From: "Paanwa" <paanwa@hotmail.com>
Subject: Custom HTTP 404 Error Redirect 
Message-Id: <3e4a439a$0$99040$a0465688@nnrp.fuse.net>

Our website has just been reorganized including the directory structure -
tons of links will now be different.  I would like to create a script that
displays a possible alternative location for a bad url (404 error).

I initially thought of making an hash of hashes that would map old and new
urls - in theory if I had the first level directories as the keys of the
hash, with corresponding subdirectories as sub hashes.

But if the wheel already exists, why reinvent it?!

Does anyone have suggestions for an existing module, or a better method?

PAW




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

Date: 12 Feb 2003 13:40:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Custom HTTP 404 Error Redirect
Message-Id: <b2dit9$664$1@mamenchi.zrz.TU-Berlin.DE>

Paanwa <paanwa@hotmail.com> wrote in comp.lang.perl.misc:
> Our website has just been reorganized including the directory structure -
> tons of links will now be different.  I would like to create a script that
> displays a possible alternative location for a bad url (404 error).
> 
> I initially thought of making an hash of hashes that would map old and new
> urls - in theory if I had the first level directories as the keys of the
> hash, with corresponding subdirectories as sub hashes.
> 
> But if the wheel already exists, why reinvent it?!
> 
> Does anyone have suggestions for an existing module, or a better method?

Why do you want to use a multi-level hash?  The mapping is from the
old URL to a (possible) new URL, it seems.  Just make a plain hash
where the old URLs are keys and the new ones are values.

You can make the hash persistent by tieing it to one of the DB_* modules.

Anno


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

Date: Wed, 12 Feb 2003 15:15:35 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Custom HTTP 404 Error Redirect
Message-Id: <Pine.LNX.4.53.0302121457110.7803@lxplus073.cern.ch>

On Feb 12, Paanwa inscribed on the eternal scroll:

Newsgrps: comp.lang.perl.modules, alt.perl, comp.lang.perl.misc

See below[1]

> Our website has just been reorganized including the directory structure -
> tons of links will now be different.  I would like to create a script that
> displays a possible alternative location for a bad url (404 error).
>
> I initially thought of making an hash of hashes that would map old and new
> urls

If you already know the relationship between old and new URLs then
instead of programming it in Perl you might be better advised to go
for a much more efficient solution: server configuration.

Apache for example supports Redirect and RedirectMatch, and if these
aren't powerful enough then mod_rewrite can do pretty-much anything,
and much more efficiently than firing-up a CGI script.  For those kind
of solutions, however, your forum would be the
comp.infosystems.www.servers.* group that's appropriate for the server
that you use, rather than here.

Let's look at your apparent intention to use a CGI script, anyway:

> - in theory if I had the first level directories as the keys of the
> hash, with corresponding subdirectories as sub hashes.

Since each invocation of the script is going to resolve just one URL,
I doubt that you really want to compute hashes for the entire server
each time.

If you can't express the relationship between old and new URLs
algorithmically (e.g with a few regexps) then maybe you're looking
for a tied hash, or some kind of simple database structure.

> But if the wheel already exists, why reinvent it?!

Good thinking.  But the requirement is a bit vague (not knowing
anything about the relationship between old and new URLs) so I'm still
suggesting you take a look at server configuration techniques first,
and the mod_rewrite documentation and recipes second.

good luck

[1]
Please, don't splatter crosspostings across closely-related
newsgroups. Choose what seems to be the most appropriate one, and stay
with it until someone who knows the ropes better guides you, when
necessary, to a better choice. Messages which are on-topic for a
*.misc group are, almost by definition, off-topic for any *.{specific}
group and vice versa, (although there are sometimes justifiable
exceptions that principle).

f'ups suggested for now.



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

Date: Wed, 12 Feb 2003 17:01:14 +0100
From: Wolfgang Fischer <Wolfgang_.fischer@freenet.de>
Subject: Re: extracting JS links with Perl
Message-Id: <pan.2003.02.12.17.01.13.982702.601@freenet.de>

Hi,
to be absolutely sure that you get all links, you have to execute the
javascript code. That's the only option to find links like that
window.open('http://www.'+'google.com/');
Maybe you can find a possibility to execute JavaScript from your perl
program. An other option would be to scan all JavaScript code for valid URLs
with a regular expression like this: /[a-zA-Z]+:\/\/[0-9a-zA-Z._]+\/[\w\/]*/
This wouldn't find URLs which are dynamically modified by the JavaScript
code.
Wolfgang

On Tue, 11 Feb 2003 18:50:31 +0100, Walter Pienciak wrote:

> Hi,
> 
> More and more I see HTML developers using embedded javascript to "link
> to" other files.
> 
> My Perl-based upload mechanisms check that links actually work, but this
> JS stuff increasingly seem to be cut-and-paste jobs with a corresponding
> increase in "broken crap" being included.
> 
> Right now, I'm dealing with it via brute-force methods -- regexps tuned
> to functions in specific .js files, where I eyeballed the link code --
> but this is like fighting the tide, and doesn't scale.
> 
> Is anyone else dealing with this problem effectively?  How? (Forbidding
> JS is just not an option for me, sorry.)
> 
> Walter


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

Date: 12 Feb 2003 15:04:08 GMT
From: ctcgag@hotmail.com
Subject: Re: Fork multiple children, read from their pipes
Message-Id: <20030212100408.632$Tt@newsreader.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Jacqui or (maybe) Pete wrote:
> > I've been trying to spawn some child processes ... Any clues / pointers
> > to resources very much welcomed.
>
> I have found the CPAN module Parallel::ForkManager useful.

I find it useful also, but not for what the poster wants to do.

Parallel::Jobs is more useful for pipes, although it does have some
quirks to it that annoy me.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Wed, 12 Feb 2003 14:07:28 +0100
From: kamran <kamran@norsar.no>
Subject: grep with line number ?
Message-Id: <3E4A4710.3301@norsar.no>

Hi

What is the equivalent for "grep -n" in perl, that is
the line number together withe expression.

thanks

Kamran


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

Date: 12 Feb 2003 14:19:00 +0100
From: mru@users.sourceforge.net (=?iso-8859-1?q?M=E5ns_Rullg=E5rd?=)
Subject: Re: grep with line number ?
Message-Id: <yw1x4r79ab7f.fsf@magnum.e.kth.se>

kamran <kamran@norsar.no> writes:

> What is the equivalent for "grep -n" in perl, that is
> the line number together withe expression.

From perlvar man page:

       input_line_number HANDLE EXPR
       $INPUT_LINE_NUMBER
       $NR
       $.      The current input record number for the last file
               handle from which you just read() (or called a
               "seek" or "tell" on).  The value may be different
               from the actual physical line number in the file,
               depending on what notion of "line" is in
               effect--see "$/" on how to change that.  An
               explicit close on a filehandle resets the line
               number.  Because "<>" never does an explicit
               close, line numbers increase across ARGV files
               (but see examples in the eof entry in the perlfunc
               manpage).  Consider this variable read-only: set­
               ting it does not reposition the seek pointer;
               you'll have to do that on your own.  Localizing
               "$."  has the effect of also localizing Perl's
               notion of "the last read filehandle".  (Mnemonic:
               many programs use "." to mean the current line
               number.)


-- 
Måns Rullgård
mru@users.sf.net


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

Date: Wed, 12 Feb 2003 14:46:00 +0100
From: kamran <kamran@norsar.no>
Subject: Re: grep with line number ?
Message-Id: <3E4A5018.342A@norsar.no>

Måns Rullgård wrote:
> 
> kamran <kamran@norsar.no> writes:
> 
> > What is the equivalent for "grep -n" in perl, that is
> > the line number together withe expression.
> 
> From perlvar man page:
> 
>        input_line_number HANDLE EXPR
>        $INPUT_LINE_NUMBER
>        $NR
>        $.      The current input record number for the last file
>                handle from which you just read() (or called a
>                "seek" or "tell" on).  The value may be different
>                from the actual physical line number in the file,
>                depending on what notion of "line" is in
>                effect--see "$/" on how to change that.  An
>                explicit close on a filehandle resets the line
>                number.  Because "<>" never does an explicit
>                close, line numbers increase across ARGV files
>                (but see examples in the eof entry in the perlfunc
>                manpage).  Consider this variable read-only: set­
>                ting it does not reposition the seek pointer;
>                you'll have to do that on your own.  Localizing
>                "$."  has the effect of also localizing Perl's
>                notion of "the last read filehandle".  (Mnemonic:
>                many programs use "." to mean the current line
>                number.)
> 
> --
> Måns Rullgård
> mru@users.sf.net


Thanks Måns

But you are talking to an illiterate :)
What I have is, I have read an entire text file into an array:
open(FILE,"$FILE");
@LINES = <FILE>;
close(FILE);
@LINES = <FILE>

and want to find the line number containg the expression "###CONTENT###"
so I can split my @LINES into two parts, one from the beginning to
the line number containing the expression and one for the remaining.

Kamran


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

Date: 12 Feb 2003 13:52:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: grep with line number ?
Message-Id: <b2djic$664$2@mamenchi.zrz.TU-Berlin.DE>

kamran  <kamran@norsar.no> wrote in comp.lang.perl.misc:
> Hi
> 
> What is the equivalent for "grep -n" in perl, that is
> the line number together withe expression.

Perl's grep() operator and the external grep command are only loosely
related.  There is no direct replacement for "-n", and "line number"
doesn't really apply because grep() works on lists, not files.

If you want the indexes of all elements of an array @array that match
/abc/a, do

    my @hits = grep $array[ $_] =~ /abc/, @list;

To retrieve the list elements, do

    my @selection = @list[ @hits];

Anno


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

Date: 12 Feb 2003 14:04:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: grep with line number ?
Message-Id: <b2dk9g$664$3@mamenchi.zrz.TU-Berlin.DE>

kamran  <kamran@norsar.no> wrote in comp.lang.perl.misc:
> Måns Rullgård wrote:
> > 
> > kamran <kamran@norsar.no> writes:
> > 
> > > What is the equivalent for "grep -n" in perl, that is
> > > the line number together withe expression.
> > 
> > From perlvar man page:
> > 
> >        input_line_number HANDLE EXPR
> >        $INPUT_LINE_NUMBER
> >        $NR
> >        $.      The current input record number for the last file
> >                handle from which you just read() (or called a
> >                "seek" or "tell" on).  The value may be different
> >                from the actual physical line number in the file,
> >                depending on what notion of "line" is in
> >                effect--see "$/" on how to change that.  An
> >                explicit close on a filehandle resets the line
> >                number.  Because "<>" never does an explicit
> >                close, line numbers increase across ARGV files
> >                (but see examples in the eof entry in the perlfunc
> >                manpage).  Consider this variable read-only: set­
> >                ting it does not reposition the seek pointer;
> >                you'll have to do that on your own.  Localizing
> >                "$."  has the effect of also localizing Perl's
> >                notion of "the last read filehandle".  (Mnemonic:
> >                many programs use "." to mean the current line
> >                number.)
> > 
> > --
> > Måns Rullgård
> > mru@users.sf.net
> 
> 
> Thanks Måns
> 
> But you are talking to an illiterate :)
> What I have is, I have read an entire text file into an array:
> open(FILE,"$FILE");
> @LINES = <FILE>;
> close(FILE);
> @LINES = <FILE>

This will destroy @LINES (and give you a warning).  I'll assume it
isn't there.

> and want to find the line number containg the expression "###CONTENT###"
> so I can split my @LINES into two parts, one from the beginning to
> the line number containing the expression and one for the remaining.

    my ( $i) = grep /###CONTENT###/, @LINES or die "no match";
    my @first = @LINES[ 0 .. $i];
    my @last = @LINES[ $i + 1 .. $#LINES];

Anno


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

Date: Wed, 12 Feb 2003 14:16:51 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: grep with line number ?
Message-Id: <3e4a566a.440566931@news.cis.dfn.de>

On Wed, 12 Feb 2003 14:07:28 +0100, kamran
<kamran@norsar.no> wrote:

>What is the equivalent for "grep -n" in perl, that is
>the line number together with the expression.

$. is the variable that contains the input line number,
thus:

#!perl
use warnings;
use strict;

my $expression = 'whatever';
my $in      = 'path/to/file';

open IN, $in or die "Cannot open $in:$!\n";
while (<IN>)
{
 print "$.\t$_" if /$expression/i;
}
__END__
-- 
Regards, Helgi Briem
helgi AT decode DOT is


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

Date: Wed, 12 Feb 2003 10:52:17 -0500
From: Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov>
Subject: Re: Insecure Filehandle Dependencies
Message-Id: <3E4A6DB1.5090608@larc.nasa.gov>

Thanks for all the replies (and bickering). The problem was with a 
system() call. I changed the one-argument call to a two-argument call, 
and everything was fine.

- Joel



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

Date: 12 Feb 2003 05:08:31 -0800
From: gohyongkwang@hotmail.com (Goh, Yong Kwang)
Subject: Minimalist Perl Interpreter for Windows 98 and XP?
Message-Id: <354933d6.0302120508.5abbdf60@posting.google.com>

Dear all,

I'm currently using ActivePerl 5 on my Win98 PC. However as I need to
run my Perl script on my school's computers which are running on Win
XP, and my system administrator doesn't allow students to install
additional software (Perl interpreter) on his computers, I can't run
my Perl program.

My script is simple without using additional modules. My script only
uses all the bulit-in features like s/// and tr/// provided by Perl to
do simple text replacement and searching.

I was thinking of rewriting the script as a C program and compile it
as a console .EXE which will run without any interpreter but decides
to give it up with the complicated text searching and parsing support
in C, the absence of regular expression support and the looming
assignment deadline :-).

So is it possible to copy all the files in /perl/bin to a CD-ROM or
ZIP disk and run it as a minimalist Perl (without setup or
installation)?

Thanks in advance.

Regards,
GOH, Yong-Kwang
Singapore
gohyongkwang@hotmail.com


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

Date: Wed, 12 Feb 2003 13:30:52 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Minimalist Perl Interpreter for Windows 98 and XP?
Message-Id: <pnik4v4nm5cknvnjcpr222jjfl79kptjup@4ax.com>

Goh, Yong Kwang wrote:

>I'm currently using ActivePerl 5 on my Win98 PC. However as I need to
>run my Perl script on my school's computers which are running on Win
>XP, and my system administrator doesn't allow students to install
>additional software (Perl interpreter) on his computers, I can't run
>my Perl program.

>So is it possible to copy all the files in /perl/bin to a CD-ROM or
>ZIP disk and run it as a minimalist Perl (without setup or
>installation)?

Uh... yes, I think perl can run from any directory. It doesn't require
any system settings, though having the perl executable in your PATH
would be nice. Otherwise, you will have to call perl with the full path
name to run a script.

If you want it even more minimal, somebody hacked a small version of
perl, small enough to put on a floppy, together with whatever modules
you desire -- in compressed format. See the latest (?) announcement and
following discussion here:

	<http://www.perlmonks.org/index.pl?node_id=225614>

-- 
	Bart.


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

Date: 12 Feb 2003 06:31:33 -0800
From: toni@mindshare.net (Toni Ellison)
Subject: mod_perl, subdomains, and cookies
Message-Id: <91e7db2.0302120631.6c842008@posting.google.com>

I've got a mod_perl module which is set to extract cookies for a
domain.  This module is setup to work for any domain name pointing to
that particular server.  If I have the domain mindshare.net, the
module can find the cookie and read it just fine.  I have created the
subdomain (dev.mindshare.net) and need to have a cookie set for it,
too.  The cookie for dev.mindshare.net will be a little different than
the one for mindshare.net.

If there is NO cookie for mindshare.net, but there is one for
dev.mindshare.net, my module will select the dev.mindshare.net cookie
for reading.  If there is a cookie for dev.mindshare.net AND
mindshare.net, the module always picks the cookie for mindshare.net
even if the request object's hostname has the value
"dev.mindshare.net".

I am using Apache's request object to obtain the cookie from the
headers like this:

$cookie = $r->headers_in->{'Cookie'};

Is there any way to force the module to pick the dev.mindshare.net
cookie if that is the hostname value?  To me it seems like Apache
should do that anyway.  I don't understand why Apache would want to
pick the cookie for mindshare.net if the hostname is dev.mindshare.net
and a dev.mindshare.net cookie exists.

Here's the code I'm using:

sub Apache::MindshareCookie::handler{
  my $r = shift;
  my %args = $r->args;

  my $hostname = $r->hostname;
  $hostname =~ s/\.//g;

  # GET A BUNCH OF VALUES FOR THIS HOSTNAME
  my $defaultvalues =  $Apache::app_globals::defaultvalues{$hostname};

  print STDERR "$hostname\n";

  # GET THE COOKIE
  $cookie = $r->headers_in->{'Cookie'};

  # DO OTHER STUFF
}

I appreciate the help.

Toni Ellison


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

Date: Wed, 12 Feb 2003 22:41:36 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: PERL JAYCAR IO Parallel
Message-Id: <O1r2a.46039$jM5.115339@newsfeeds.bigpond.com>

Anyone used parallel port and perl ?

I want to control relays



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

Date: Wed, 12 Feb 2003 12:20:21 +0100
From: Josef =?iso-8859-1?Q?M=F6llers?= <josef.moellers@fujitsu-siemens.com>
Subject: Re: Perl script to create new user in Linux.
Message-Id: <3E4A2DF5.90E2D6E7@fujitsu-siemens.com>

Kjetil wrote:
> =

> Hello!
> =

> Does anyone have a Perl-script (or a receipt) to make new Linux-users?

Hmmm, new Linux-users aren't made with Perl-Scripts. Pearls might help,
though.

SCNR,

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Wed, 12 Feb 2003 12:38:35 +0100
From: Eric Moors <scare.crow@oz.land>
Subject: Re: Perl script to create new user in Linux.
Message-Id: <pan.2003.02.12.12.38.27.366534.11292@oz.land>

On Wed, 12 Feb 2003 11:05:54 +0100, Kjetil wrote:

> Hello!
> 
> Does anyone have a Perl-script (or a receipt) to make new Linux-users? I

Making new users involves having sex. I don't think a perl script will do

> would really appreciate it if I could have a copy :-) Please send a copy
> of answers to my email-adress.  I'm using SUSE 7.3.

What's wrong with useradd/adduser

Eric


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

Date: Wed, 12 Feb 2003 11:51:37 -0000
From: wcitoan@NOSPAM-yahoo.com (W. Citoan)
Subject: Re: Perl script to create new user in Linux.
Message-Id: <v4kda94e4sio98@corp.supernews.com>

On Wed, 12 Feb 2003 11:05:54 +0100, Kjetil wrote:

>  Does anyone have a Perl-script (or a receipt) to make new Linux-users?  I
>  would really appreciate it if I could have a copy :-) Please send a copy of
>  answers to my email-adress.  I'm using SUSE 7.3.

Better option would be to just have perl call an existing system
command (i.e. useradd)...

- W. Citoan


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

Date: Wed, 12 Feb 2003 16:21:56 +0100
From: "Kjetil" <kjetil.klove@nrk.no>
Subject: Re: Perl script to create new user in Linux.
Message-Id: <WEt2a.27139$Rc7.391732@news2.e.nsc.no>

Ok, I suppose I should ask for a shell-script then.

Kjetil

"Josef Möllers" <josef.moellers@fujitsu-siemens.com> skrev i melding
news:3E4A2DF5.90E2D6E7@fujitsu-siemens.com...
Kjetil wrote:
>
> Hello!
>
> Does anyone have a Perl-script (or a receipt) to make new Linux-users?

Hmmm, new Linux-users aren't made with Perl-Scripts. Pearls might help,
though.

SCNR,

--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T.  Pratchett




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

Date: Wed, 12 Feb 2003 08:04:09 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: print <<HERE;
Message-Id: <slrnb4kl2p.3gv.tadmc@magna.augustmail.com>

istink <istink@real.bad.com> wrote:
> print <<HERE;
> will print
> this
> stuff
> up
> to
> HERE
> 
> 
> is this possible?
> pseudo code:
> $thisthing <<HERE;  (or @thisthing perhaps)
> blah
> blah
> zzzzzzzzzz
> HERE


You do not have the correct mental model of what here-docs are.

Here-docs are simply an alternative way of quoting a string.

Think of what you want to do as a plain ol' quoted string. 

Can you do:

   print "stuff"

Yep, so you can replace the "stuff" with a here-doc.

Can you do:

   $thisthing "stuff"

Nope, so it ain't gonna work. You _can_ do:

   $thisthing = "stuff"

though, so replace the "stuff" with a here-doc:

$thisthing =<<HERE;
blah
HERE


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


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

Date: Wed, 12 Feb 2003 09:28:08 -0500
From: Shane McDaniel <shanem@nospam.ll.mit.edu>
Subject: Re: print <<HERE;
Message-Id: <3E4A59F8.F7382EB6@nospam.ll.mit.edu>



istink wrote:
> 
> print <<HERE;
> will print
> this
> stuff
> up
> to
> HERE
> 
> is this possible?
> pseudo code:
> $thisthing <<HERE;  (or @thisthing perhaps)
> blah
> blah
> zzzzzzzzzz
> HERE
> 
> I know it won't work literally.


According to the Camel Book 3rd ed pg 67   you need an = sign

$foo = <<HERE
etc...

-shane


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

Date: Wed, 12 Feb 2003 15:21:05 GMT
From: ebchang <chang0@adelphia.net>
Subject: puzzling operator priorities
Message-Id: <Xns9320694C7EFF9chang0adelphia.net@24.48.107.53>

Looking at the expression $x = 5 && $y = 7,  I thought it would be 
parenthesized as either ($x = (5 && $y)) = 7 or as $x = (5 && $y)) = 7) 
since && has higher priority than assignment.  

However the resulting values for $x and $y are 7 and 7 respectively, the 
result produced by parenthesizing it as $x = (5 && ($y = 7)).  No matter 
how much I reread perlop, I can't come up with a reason.  ($x = (5 && $y)) 
= 7 results in values of 7 and undef,  and $x = ((5 && $y) = 7) in 1 and 7.  

I'm guessing that this is an instance of DWIM, and would welcome further 
illumination.

-- 
EBC


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

Date: Wed, 12 Feb 2003 12:18:06 -0000
From: "Brian Smart" <brian.smart@blueyonder.co.uk>
Subject: Re: Re Installing modules from CPAN
Message-Id: <5Pq2a.6636$217.2695@news-binary.blueyonder.co.uk>

Hello Tad,
I wanted to use the thread but my original posting had disappeared when I
tried to use it.

Could I ask another question. When I tried to install a different module all
went well until the message

' There's a new CPAN.pm version (v1.65) available!
  You might want to try
    install Bundle::CPAN
    reload cpan
  without quitting the current session. It should be a seamless upgrade
  while we are running...

Fetching with LWP:
  ftp://ftp.demon.co.uk/pub/CPAN/modules/03modlist.data.gz
Going to read y/sources/modules/03modlist.data.gz
Running make for I/IL/ILYAZ/modules/Math-Pari-2.010305.tar.gz
CPAN: MD5 loaded ok
Could not gzopen
y/sources/authors/id/I/IL/ILYAZ/modules/Math-Pari-2.010305.tar.gz at
/usr/lib/perl5/5.00503/CPAN.pm line 4159.
[bsmart Net-SSH-Perl-1.23]$'

I then can't make any further progress. Can you advise what I might be doing
wrong?

Thanks for your help.

Regards

Brian Smart

"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnb4hvhf.3at.tadmc@magna.augustmail.com...
> Brian Smart <brian.smart@blueyonder.co.uk> wrote:
>
> > Thanks for the help especially from Tad McClellan.
>
>
> You're welcome.
>
> You should have made your followup in the same thread where
> the discussion took place though, rather than starting a
> new disconnected thread.
>
> And you shouldn't put Re in the Subject when you don't make
> reference to any previous post.
>
> And you shouldn't change the Subject unless you are really
> changing the subject.  :-)
>
> Threading is useful. Please don't break it.
>
>
> --
>     Tad McClellan                          SGML consulting
>     tadmc@augustmail.com                   Perl programming
>     Fort Worth, Texas




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

Date: 12 Feb 2003 15:11:36 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: Re Installing modules from CPAN
Message-Id: <slrnb4koke.4up.randy@theoryx5.uwinnipeg.ca>

On Wed, 12 Feb 2003 12:18:06 -0000, 
   Brian Smart <brian.smart@blueyonder.co.uk> wrote:
>Could I ask another question. When I tried to install a different 
>module all went well until the message
>
>Fetching with LWP:
>  ftp://ftp.demon.co.uk/pub/CPAN/modules/03modlist.data.gz
>Going to read y/sources/modules/03modlist.data.gz
>Running make for I/IL/ILYAZ/modules/Math-Pari-2.010305.tar.gz
>CPAN: MD5 loaded ok
>Could not gzopen
>y/sources/authors/id/I/IL/ILYAZ/modules/Math-Pari-2.010305.tar.gz at
>/usr/lib/perl5/5.00503/CPAN.pm line 4159.
>[bsmart Net-SSH-Perl-1.23]$'

It's trying to read a file in a directory 'y', which most likely
you don't have. This is probably due to a stray 'y' getting
written to CPAN.pm's Config.pm - either edit this file
(or $HOME/.cpan/CPAN/MyConfig.pm, if you use that) to get
rid of the 'y', or else reconfigure things via
  bash$ perl -MCPAN -e shell
  cpan> o conf init

-- 
best regards,
randy kobes


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

Date: Wed, 12 Feb 2003 07:58:11 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Request help with this script
Message-Id: <slrnb4kknj.3gv.tadmc@magna.augustmail.com>

Jay Tilton <tiltonj@erols.com> wrote:

> 2. use strict;
> 
> That one deserves the most attention.  The way the program uses
> symbolic references creates gaping holes that allow the user to change
> a lot of what goes on in the program.


For more insight on the dangers of mucking about with the
symbol table (symrefs), see:

   http://www.plover.com/~mjd/perl/varvarname.html
   http://www.plover.com/~mjd/perl/varvarname2.html
   http://www.plover.com/~mjd/perl/varvarname3.html



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


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

Date: 12 Feb 2003 12:01:35 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: strict and warnings
Message-Id: <b2dd2v$15p$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Bart Lateur:

> Tassilo v. Parseval wrote:
> 
>>What you say is that you prefer warning messages pop up all over the
>>place whenever something unexpected but harmless has happened on the
>>internals.
> 
> Not so. For example, I use XML::Writer, to er, generate XML --
> obviously, and *it* produces warnings internally if *my* data I pass it
> is undefined. I should not do that. It would have been better still if
> it used Carp for that, and pointed to the place in *my* script where I
> call XML::Writer's methods in an unclean way. But still, this is
> something, indicating *something* is wrong with my data, somewhere.

Something somewhere, yes. I think this is not quite the case I was
thinking of. Carp.pm is exactly for the above: A not quite consistent
state within the module that is caused by the way a user works with the
module. Warnings inside the module don't achieve the above since they
don't give the proper feedback to the user. They tell him that some
value was undefined in line soandso inside the module...but instead they
should give the line number inside the script.

Hmmh, how about this in a module:

    use warnings;
    $SIG{ __WARN__ } = sub { carp @_ }; # or even cluck() possibly
    
When using carp() like that, will it still report the correct place in
the script where the warning was caused in the first place or will it be
confused by the fact that it is called from a __WARN__ handler?

I could very easily live with the above (provided it works) since this
really gives useful information to the user. My main concern with simply
using warnings is that the result is too unspecific (almost
coincidental) to be useful.

> If you want to go ahead and abuse a module, you can still localise
> warnings in the block where you call the module, by doing
> 
> 	{
> 	    local $^W;
> 	    ...  #some quircky code
> 	}
> 
> I don't know what this does in relation to "use warnings", I don't use
> it that often -- or even, at all. I thought the latter was lexical in
> nature. Hmm...

The warnings-pragma is...but I've no idea at all in which way it relates
to $^W. Apparently not at all. The following test suggests that you
can't mix them sensibly:

    { use warnings;
      local $^W;
      print undef; }
    __END__
    Use of uninitialized value in print at - line 3.

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, 12 Feb 2003 08:43:37 -0500
From: Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov>
Subject: Subs in external files?
Message-Id: <3E4A4F89.1000801@larc.nasa.gov>

How do I call a sub from an external file? Or sould I need to create a 
module to do that?

- Joel



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

Date: Wed, 12 Feb 2003 16:48:52 +0100
From: Wolfgang Fischer <Wolfgang_.fischer@freenet.de>
Subject: Re: Subs in external files?
Message-Id: <pan.2003.02.12.16.48.52.627037.601@freenet.de>

On Wed, 12 Feb 2003 14:43:37 +0100, Joel Konkle-Parker wrote:

> How do I call a sub from an external file? Or sould I need to create a
> module to do that?
> 
> - Joel

hi,
maybe you should use the module AutoLoader. See perldoc Autoloader for
more details

- Wolfgang


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

Date: Wed, 12 Feb 2003 10:50:59 -0500
From: Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov>
Subject: Re: Subs in external files?
Message-Id: <3E4A6D63.7010808@larc.nasa.gov>

Joel Konkle-Parker wrote:

> How do I call a sub from an external file? Or sould I need to create a 
> module to do that?
> 
> - Joel
> 

I just answered my own question. For future reference:

just use a require "path/sub.pl"; then call the sub like normal

- joel



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

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


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