[22136] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4357 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 7 09:06:56 2003

Date: Tue, 7 Jan 2003 06: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           Tue, 7 Jan 2003     Volume: 10 Number: 4357

Today's topics:
        Detecting media change/closing of CD tray? <spamfilter@cheiron-it.nl>
    Re: Detecting media change/closing of CD tray? <nobull@mail.com>
    Re: Detecting media change/closing of CD tray? <ubl@schaffhausen.de>
    Re: Detecting media change/closing of CD tray? <spamfilter@cheiron-it.nl>
    Re: Detecting media change/closing of CD tray? <spamfilter@cheiron-it.nl>
    Re: Noob:  Variable is getting reset, but why? (Tad McClellan)
        Perl quotations problem <cmps7331@hotmail.com>
    Re: Perl quotations problem <ian@WINDOZEdigiserv.net>
    Re: Perl quotations problem <ian@WINDOZEdigiserv.net>
    Re: Perl quotations problem <nobody@dev.null>
    Re: Queer behavior (Mandar Amdekar)
    Re: reading output of tar in blocks <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: reading output of tar in blocks <mzawadzk@man.poznan.pl>
    Re: reading output of tar in blocks <nobull@mail.com>
        Reg Expression help <scoutts.work@btinternet.com>
    Re: Reg Expression help (Anno Siegel)
    Re: Reg Expression help <scoutts.work@btinternet.com>
    Re: regexp question (Tad McClellan)
    Re: Regular expression for stopword removal (Helgi Briem)
        translating script using getopts  from sh to perl (gilles)
        using subroutines defined in other scripts <jvandervloet@hotmail.com>
    Re: using subroutines defined in other scripts (Anno Siegel)
    Re: using subroutines defined in other scripts <nobull@mail.com>
    Re: using subroutines defined in other scripts (Sam Holden)
    Re: using subroutines defined in other scripts <jvandervloet@hotmail.com>
    Re: using subroutines defined in other scripts (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 7 Jan 2003 13:29:28 +0100
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: Detecting media change/closing of CD tray?
Message-Id: <3e1ac87c$0$140$e4fe514c@dreader7.news.xs4all.nl>

Hi,

 I tried to find something on this subject on the web, but probably used
the wrong keywords. What I want to do is detect if someone closes the
CD-ROM player (on a laptop) from within Perl. Since it is not certain
that a CD is placed in it, I cannot simply check for the capacity or
such a thing.
The system is running Linux, kernel 2.4.17. My search included 'how does
Linux tell me...', but that did not result in something useful either.

I would be delighted if you could help me on this!

Frank





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

Date: 07 Jan 2003 12:10:45 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <u9vg11qhx6.fsf@wcl-l.bham.ac.uk>

"Frank Maas" <spamfilter@cheiron-it.nl> writes:

> I tried to find something on this subject on the web, but probably used
> the wrong keywords. What I want to do is detect if someone closes the
> CD-ROM player (on a laptop) from within Perl. Since it is not certain
> that a CD is placed in it, I cannot simply check for the capacity or
> such a thing.

This probably has a lot more to do with the OS you are using than it
has to do with Perl.

First find out how the OS you use notifies applications about CD
change, then come here to ask how to interface to that in Perl.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 07 Jan 2003 13:21:52 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <avek1e$rb1$1@news.dtag.de>

Frank Maas wrote:
> Hi,
> 
> I tried to find something on this subject on the web, but probably used
> the wrong keywords. What I want to do is detect if someone closes the
> CD-ROM player (on a laptop)

This is probably very OS dependent, eg handles differently under MacOS 
and Linux, so you should tell us which OS you are using or whether you 
need a universal solution.

->malte

-- 
srand 108641088; print chr int rand 256 for qw<J A P H>



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

Date: Tue, 7 Jan 2003 13:28:04 +0100
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <3e1ac828$0$151$e4fe514c@dreader7.news.xs4all.nl>


"Brian McCauley" <nobull@mail.com> schreef in bericht
news:u9vg11qhx6.fsf@wcl-l.bham.ac.uk...
> "Frank Maas" <spamfilter@cheiron-it.nl> writes:
>
> > I tried to find something on this subject on the web, but probably used
> > the wrong keywords. What I want to do is detect if someone closes the
> > CD-ROM player (on a laptop) from within Perl. Since it is not certain
> > that a CD is placed in it, I cannot simply check for the capacity or
> > such a thing.
>
> This probably has a lot more to do with the OS you are using than it
> has to do with Perl.
>
> First find out how the OS you use notifies applications about CD
> change, then come here to ask how to interface to that in Perl.

Sorry about that, a phrase got lost... The laptop is running Linux,
kernel 2.4.17. Unfortunately I did not find information on how Linux
is telling me that the tray was closed, that's why I hoped someone in
the Perl community would be able to help. But if I then do not specify
my OS...

Frank




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

Date: Tue, 7 Jan 2003 13:28:16 +0100
From: "Frank Maas" <spamfilter@cheiron-it.nl>
Subject: Re: Detecting media change/closing of CD tray?
Message-Id: <3e1ac834$0$144$e4fe514c@dreader7.news.xs4all.nl>


"Malte Ubl" <ubl@schaffhausen.de> schreef in bericht
news:avek1e$rb1$1@news.dtag.de...
> Frank Maas wrote:
> > Hi,
> >
> > I tried to find something on this subject on the web, but probably used
> > the wrong keywords. What I want to do is detect if someone closes the
> > CD-ROM player (on a laptop)
>
> This is probably very OS dependent, eg handles differently under MacOS
> and Linux, so you should tell us which OS you are using or whether you
> need a universal solution.
>


Sorry about that, a phrase got lost... The laptop is running Linux,
kernel 2.4.17. Unfortunately I did not find information on how Linux
is telling me that the tray was closed, that's why I hoped someone in
the Perl community would be able to help. But if I then do not specify
my OS...

Frank




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

Date: Tue, 7 Jan 2003 06:43:40 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Noob:  Variable is getting reset, but why?
Message-Id: <slrnb1lirs.fgl.tadmc@magna.augustmail.com>

Joe Smith <inwap@inwap.com> wrote:

> The while(<INPUT>) statement does an
> implicit open() of each file named on the command line.


No, that's the    while(<>)    statement that does that.  :-)


(actually any use of the <> diamond operator does that, whether
 in a while or elsewhere.
)

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


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

Date: Tue, 7 Jan 2003 07:21:02 -0600
From: "Cmps" <cmps7331@hotmail.com>
Subject: Perl quotations problem
Message-Id: <avejvc$bea$1@saluki-news.it.siu.edu>

I am not sure about the compatibility possibilities, but I have encountered
the following error when testing Perl/CGI scripts on ActivePerl versus
actual server running.  The following is an example:

$str1="friendlynospam"+"@"+".org";
$str2="filename.ext";

Note the quoatations in split quotations in $str1 and no-split in $str2.
$str2 is a whole string, commonly recognized.  $str1 is a broken string, but
usually excepted by most scripts.  Now if you test it on ActivePerl, it
executes ok.  However, attempting to run this on the server, it will not
execute.  When correctly changed to $str1='friendlynospam'+'@'+'.org' it
amazingly works.  Other quoation rules do not matter as they work fine.  But
firstly, single quotes are commonly for character referencing though I know
in Perl and scripts this is not always true.  But why then is this not
allowed in the joining of quotations in the first manner with $str1.  Is
there some rule about Perl here?

The point of the matter is you can debug for hours and miss this one point.





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

Date: Tue, 07 Jan 2003 13:34:58 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Perl quotations problem
Message-Id: <2oll1vse9llomb6iu5c58hnp2n8h8okvcc@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Tue, 7 Jan 2003 07:21:02 -0600, "Cmps"
<cmps7331@hotmail.com> managed to scribble:

> I am not sure about the compatibility possibilities, but I have
> encountered the following error when testing Perl/CGI scripts on
> ActivePerl versus actual server running.  The following is an
> example:
> 
> $str1="friendlynospam"+"@"+".org";
> $str2="filename.ext";
> 
> Note the quoatations in split quotations in $str1 and no-split in
> $str2. $str2 is a whole string, commonly recognized.  $str1 is a
> broken string, but usually excepted by most scripts.  Now if you test
> it on ActivePerl, it executes ok.  However, attempting to run this on
> the server, it will not execute.  When correctly changed to
> $str1='friendlynospam'+'@'+'.org' it amazingly works.  Other quoation
> rules do not matter as they work fine.  But firstly, single quotes
> are commonly for character referencing though I know in Perl and
> scripts this is not always true.  But why then is this not allowed in
> the joining of quotations in the first manner with $str1.  Is there
> some rule about Perl here?
> 
> The point of the matter is you can debug for hours and miss this one
> point.  
> 
> 


$str1 = "friendlynospam" . "\@" . ".org";

It appears that the above example is trying to add values of a string
rather than concatenating.

Using + to concat a string looks very ASP/VB to me.



Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPhrXfWfqtj251CDhEQJW3ACeL7bTtn8C1C/HokWTtN2TvtcfLQoAoJI1
9vJSLuJQMhGYTa/Jzc++wUCY
=X6Iz
-----END PGP SIGNATURE-----

-- 
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Tue, 07 Jan 2003 13:37:16 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Perl quotations problem
Message-Id: <jtll1vcd95q2t8n2hukj9q39hgnruiekik@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Tue, 07 Jan 2003 13:34:58 GMT, "Ian.H [dS]"
<ian@WINDOZEdigiserv.net> managed to scribble:


[ snip ]


> The following is an example:
> > 
> > $str1="friendlynospam"+"@"+".org";
> > $str2="filename.ext";
> > 


[ snip ]


> 
> $str1 = "friendlynospam" . "\@" . ".org";
> 
> It appears that the above example is trying to add values of a string
> rather than concatenating.


The "above example" in my post was referring to your supplied example,
although I didn't make it clear.




Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP Personal Privacy 6.5.3

iQA/AwUBPhrYCGfqtj251CDhEQLX/ACfTKwl1G6uZ24+9ge2eF7eBYYcpPsAn1R4
x7jGm+/qsRPxK9/ah5+eB069
=xY+C
-----END PGP SIGNATURE-----

-- 
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Tue, 07 Jan 2003 14:02:58 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Perl quotations problem
Message-Id: <3E1ADD41.5040301@dev.null>



Cmps wrote:

> I am not sure about the compatibility possibilities, but I have encountered
> the following error when testing Perl/CGI scripts on ActivePerl versus
> actual server running.  The following is an example:
> 
> $str1="friendlynospam"+"@"+".org";
> $str2="filename.ext";
> 
> Note the quoatations in split quotations in $str1 and no-split in $str2.
> $str2 is a whole string, commonly recognized.  $str1 is a broken string, but
> usually excepted 

What does this mean? The script raises an exception? Or do you mean 
"accepted"?

> by most scripts.  Now if you test it on ActivePerl, it
> executes ok.  However, attempting to run this on the server, it will not
> execute.  When correctly changed to $str1='friendlynospam'+'@'+'.org' it
> amazingly works.  


I'm not sure what "amazingly works" is supposed to mean, but $str1=0; 
would have been a much more succinct way of setting $str1 to zero. You 
see, in Perl the operator for string concatenation (which is presumably 
what you are looking for) is the dot (.). The plus sign (+) is used for 
adding numbers. So when you say

$str1='friendlynospam'+'@'+'.org';

you are really taking three non-numeric strings, use a numeric operator 
in them, which converts them to 0, and then add them up, giving you, in 
essence, $str1=0+0+0.

Perl would have told you that, had you used warnings.





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

Date: 7 Jan 2003 05:47:37 -0800
From: mandar_amdekar@hotmail.com (Mandar Amdekar)
Subject: Re: Queer behavior
Message-Id: <abe1bc22.0301070547.2a082e8f@posting.google.com>

"John W. Krahn" <krahnj@acm.org> wrote in message news:<3E19AF17.5ED0CF5E@acm.org>...
> Mandar Amdekar wrote:
> > 
> > I'm using as perl v5.6.1 built for MSWin32-x86-multi-thread
> > 
> > Here are 2 ways of writing the same small program:
> > 1>
> > print("Input: ");
> > my($var) = <STDIN>;
> > print("Your input = $var\n");
> > 
> > 2>
> > print("Input: ");
> > my($var);
> > $var = <STDIN>;
> > print("Your input = $var\n");
> > 
> > When I run 1, the <ENTER> does not end the stdin steam, which is not
> > what I want, but program 2 does end the stdin steam on hitting
> > <ENTER>.
> > 
> > Is this expected behavior? And if so, why?
> 
> Yes it is.  Because the parenthesis force a list context which requires
> you to send an EOF signal (Ctrl-D in *nix or Ctrl-Z in Windows.)  Just
> remove all the parenthesis.
> 
> print "Input: ";
> my $var = <STDIN>;
> print "Your input = $var\n";
> 
> 
> 
> John

Thanks for the reply. It makes sense now.
-Mandar


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

Date: Tue, 07 Jan 2003 12:56:43 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: reading output of tar in blocks
Message-Id: <newscache$jiec8h$1s5$1@news.emea.compuware.com>

Marek Zawadzki wrote (Tuesday 07 January 2003 11:15):

> Hello,
> 
> I'm creating a large tar file and I want to read tar's output, split it
> into fragments and send each fragment to the remote site without making
> local copy for the entire tarball (thus split command doesn't suit me).
> I need something like this:
> 
> while (read(`tar -cf - local_file`), $buffer, $BLOCK_SIZE) {
> do_something_with_buffer;
> }
> 
> I'll appreciate any hints,
> 
> -marek
> (also posted on alt.perl)


Although an entirely different approach, doesn't the rsh command suit your 
needs?  Such as:
tar ... | rsh remote_host tar ...

-- 
KP



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

Date: Tue, 7 Jan 2003 13:09:39 +0100
From: Marek Zawadzki <mzawadzk@man.poznan.pl>
Subject: Re: reading output of tar in blocks
Message-Id: <Pine.GSO.4.44.0301071304150.6526-100000@rose.man.poznan.pl>

On Tue, 7 Jan 2003, Koos Pol wrote:

> Marek Zawadzki wrote (Tuesday 07 January 2003 11:15):
/ ...
> > while (read(`tar -cf - local_file`), $buffer, $BLOCK_SIZE) {
> > do_something_with_buffer;
> > }
/ ...
> Although an entirely different approach, doesn't the rsh command suit your
> needs?  Such as:
> tar ... | rsh remote_host tar ...

No. I should have mentioned I can use ftp only and _have_ to split the
file due to the ftp server's characteristic.
I've found the solution already though:

open(TAR, "tar -cf - $local_file|");

and then I'm reading from TAR, splitting the output and sending pieces one
by one.

Any comments to this ($local_file will be large -- often more than 1GB --
don't want to eat too much memory) aprectiated.
As well as a different approach.

-marek



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

Date: 07 Jan 2003 12:12:08 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: reading output of tar in blocks
Message-Id: <u9ptr9qhuv.fsf@wcl-l.bham.ac.uk>

Marek Zawadzki <mzawadzk@man.poznan.pl> writes:

> I need something like this:
> 
> while (read(`tar -cf - local_file`), $buffer, $BLOCK_SIZE) {
> 	do_something_with_buffer;
> }
> 
> I'll appreciate any hints,

perldoc -f open

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 7 Jan 2003 13:58:51 -0000
From: "Steven Coutts" <scoutts.work@btinternet.com>
Subject: Reg Expression help
Message-Id: <3e1add2e@nntp.onyx.net>

Just a quickie, been puzzling over this I'm not too hot on regular
expressions, how would I write a reg exp to replace '+' signs with spaces?


Cheers for any help


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.435 / Virus Database: 244 - Release Date: 30/12/2002




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

Date: 7 Jan 2003 14:02:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Reg Expression help
Message-Id: <avemkp$5pr$3@mamenchi.zrz.TU-Berlin.DE>

Steven Coutts <scoutts.work@btinternet.com> wrote in comp.lang.perl.misc:
> Just a quickie, been puzzling over this I'm not too hot on regular
> expressions, how would I write a reg exp to replace '+' signs with spaces?

What have you tried, and where's the problem?

Anno


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

Date: Tue, 7 Jan 2003 14:03:39 -0000
From: "Steven Coutts" <scoutts.work@btinternet.com>
Subject: Re: Reg Expression help
Message-Id: <3e1ade4c$1@nntp.onyx.net>

Tried   /\+\+S/



"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:avemkp$5pr$3@mamenchi.zrz.TU-Berlin.DE...
> Steven Coutts <scoutts.work@btinternet.com> wrote in comp.lang.perl.misc:
> > Just a quickie, been puzzling over this I'm not too hot on regular
> > expressions, how would I write a reg exp to replace '+' signs with
spaces?
>
> What have you tried, and where's the problem?
>
> Anno


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.435 / Virus Database: 244 - Release Date: 30/12/2002




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

Date: Tue, 7 Jan 2003 06:31:53 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regexp question
Message-Id: <slrnb1li5p.fgl.tadmc@magna.augustmail.com>

C3 <someone@microsoft.com> wrote:
> Thanks for that. For some reason I'd forgotten that ^ was used for negation
> as well. I'd gotten so used to using it for the start of the line.


And for bitwise xor.  :-)

Caret has 3 meanings in 3 of the languages in Perl.

   in Perl          bitwise xor

   in regex         start of string

   in char class    negates class

You need to pay attention to what language you are in to know
what semantics go with each funny character.


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


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

Date: Tue, 07 Jan 2003 11:13:05 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Regular expression for stopword removal
Message-Id: <3e1ab2e6.287717345@news.cis.dfn.de>

On Tue, 07 Jan 2003 10:34:28 +0000, Fergus Toolan
<fergus.toolan@ucd.ie> wrote:

>I'm writing an Information Retrieval System using PERL. 

It's Perl or perl, never PERL.  It's not an acronym.

>I'm trying to remove stopwords from the text I have.

>In the following code snippets $text is the document contents and 
>$stopword is the word I'm trying to remove.
>
>My first attempt was just
>
>	$text =~ s/$stopword//ig;
>
>Of course this removed all occurrences of the stopword from the text 
>including any occurrences of a stopword in another word in the text.
>So for instance every letter 'a' in the text was removed.

What you want is \b for "word boundary", thus:

$text =~ s/\b$stopword\b//ig;

If you want to replace it with a space:

$text =~ s/\b$stopword\b/ /ig;

>Also if anyone knows of any good introductory web resources to regular 
>expressions I would be grateful if you could send them on.

Every Perl installation comes with a plethora of
excellent documentation and a program, 'perldoc'
for accessing and searching it. Type perldoc STRING
on the command line to use it, perldoc -f FUNCTION 
gives you information on a function, perldoc DOC gives
you a particular document and perldoc -q KEYWORD
finds a question in the Frequently Asked Question
documents.  The popular Activestate Perl distribution
comes with all the documentation in html form in
C:/Perl/html.

See 
'perldoc perl'  and 'perldoc perldoc' for details
on how to use perldoc

'perldoc perlrequick' contains a quick regular
expression tutorial and 'perldoc perlre' a more
comprehensive treatment.

I hope this helps.
-- 
Regards, Helgi Briem
helgi AT decode DOT is


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

Date: 7 Jan 2003 03:38:52 -0800
From: gbourgeois@yaccom.com (gilles)
Subject: translating script using getopts  from sh to perl
Message-Id: <5c15d48f.0301070338.72e0aaa7@posting.google.com>

hello, I am a newbie in perl, and I want to translate the following
getopts "sh like " scripts in perl using Getopt::Std;
but I did not find a good example, although I think my script could be
straightely traslated into perl:

# Parse command line
while getopts "df:ghkm:nst:uv:" c ; do
	case "$c" in
	d)	makeflags="$makeflags -d" ;;
	f)	genfile="$OPTARG" ;;
	g)	forcegmake="YES" ;;
	h)	usage ; targets ; echo >&2 ; variants ; exit 0 ;;
	k)	makeflags="$makeflags -k" ;;
	m)	modlist="$OPTARG" ;;
	n)	makeflags="$makeflags -n" ;;
	s)	makeflags="$makeflags -s" ;;
	t)	target="$OPTARG" ;;
	u)	makeflags="$makeflags -u" ;;
	v)	variantfile="$OPTARG" ;;
	*)	usage ; exit 1 ;;
	esac
done


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

Date: Tue, 07 Jan 2003 11:54:23 GMT
From: "joeri" <jvandervloet@hotmail.com>
Subject: using subroutines defined in other scripts
Message-Id: <PdzS9.93793$Ti2.13244@afrodite.telenet-ops.be>

Hi,

I have a particular perl script, which contains some useful subroutines such
as:

sub pushnew (\@@) {
    my $array = shift;
    while (@_) {
        push @$array, $_[0] unless grep $_[0] eq $_, @$array;
        shift;
    }
}



When I start writing a new script, I don't want to restate this subroutine
every time in each new script (when needed).

What I would like to be able to do is just let the new script 'use' the
subroutines stated in this subroutine-gathering

script. I've looked at 'require' and Autoloader, but I just can't seem to
find a straightforward answer to this question.

Any of you have any idea?



Thanks,



J.




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

Date: 7 Jan 2003 12:08:25 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: using subroutines defined in other scripts
Message-Id: <avefvp$5pr$1@mamenchi.zrz.TU-Berlin.DE>

joeri <jvandervloet@hotmail.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> I have a particular perl script, which contains some useful subroutines such
> as:
> 
> sub pushnew (\@@) {
>     my $array = shift;
>     while (@_) {
>         push @$array, $_[0] unless grep $_[0] eq $_, @$array;
>         shift;
>     }
> }
> 
> 
> 
> When I start writing a new script, I don't want to restate this subroutine
> every time in each new script (when needed).
> 
> What I would like to be able to do is just let the new script 'use' the
> subroutines stated in this subroutine-gathering
> 
> script. I've looked at 'require' and Autoloader, but I just can't seem to
> find a straightforward answer to this question.

Forget about Autoloader for the moment, that's an optional extension
of the mechanism.

"require" goes in the right direction, but what most people use for
your purpose is "use" (perldoc -f use) combined with Exporter (perldoc
Exporter).  See "perldoc perlmod" for how to put them together.

Anno


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

Date: 07 Jan 2003 12:08:40 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: using subroutines defined in other scripts
Message-Id: <u9znqdqi0n.fsf@wcl-l.bham.ac.uk>

"joeri" <jvandervloet@hotmail.com> writes:

> I have a particular perl script, which contains some useful subroutines such
> as:
> 
> sub pushnew (\@@) {
>     my $array = shift;
>     while (@_) {
>         push @$array, $_[0] unless grep $_[0] eq $_, @$array;
>         shift;
>     }
> }
> 
> 
> 
> When I start writing a new script, I don't want to restate this subroutine
> every time in each new script (when needed).
> 
> What I would like to be able to do is just let the new script 'use' the
> subroutines stated in this subroutine-gathering
> script. I've looked at 'require' and Autoloader, but I just can't seem to
> find a straightforward answer to this question.

Do not look at Autoloader - it doesn't really relate to your question.

If you write a Perl 'script' that just defines subroutines (and maybe
initialises some variables) but doesn't actually do anything
substantive you can simply require() it then call functions from it.
Such a script is not really a script in it's own right but is a
Perl4-style library.

When working with Perl5 it is better to use Perl5 modules and the
Exporter module.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 7 Jan 2003 12:11:49 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: using subroutines defined in other scripts
Message-Id: <slrnb1lh05.rfm.sholden@flexal.cs.usyd.edu.au>

On Tue, 07 Jan 2003 11:54:23 GMT, joeri <jvandervloet@hotmail.com> wrote:
> Hi,
> 
> I have a particular perl script, which contains some useful subroutines

[snip]

> When I start writing a new script, I don't want to restate this subroutine
> every time in each new script (when needed).
> 
> What I would like to be able to do is just let the new script 'use' the
> subroutines stated in this subroutine-gathering
> 
> script. I've looked at 'require' and Autoloader, but I just can't seem to
> find a straightforward answer to this question.
> 
> Any of you have any idea?

require does the job, just require 'subs.pl'; in the script.

Read the require description in the perlfunc documentation, since there's
an important 'must return true' bit...

-- 
Sam Holden



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

Date: Tue, 07 Jan 2003 13:04:42 GMT
From: "joeri" <jvandervloet@hotmail.com>
Subject: Re: using subroutines defined in other scripts
Message-Id: <KfAS9.93919$Ti2.13364@afrodite.telenet-ops.be>

OK,

suppose this is what the subs file has:

sub pushnew (\@@) {
    my $array = shift;
    while (@_) {
        push @$array, $_[0] unless grep $_[0] eq $_, @$array;
        shift;
    }
}
1;

In a new script, I write the following:

require "c:/perl/lib/subs/perlsubs.pl";

@seen = qw/I have/;
pushnew(@seen, "seen");
print "@seen\n";

This should print "I have seen" normally, but it just prints "I have".

How come?

"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnb1lh05.rfm.sholden@flexal.cs.usyd.edu.au...
> On Tue, 07 Jan 2003 11:54:23 GMT, joeri <jvandervloet@hotmail.com> wrote:
> > Hi,
> >
> > I have a particular perl script, which contains some useful subroutines
>
> [snip]
>
> > When I start writing a new script, I don't want to restate this
subroutine
> > every time in each new script (when needed).
> >
> > What I would like to be able to do is just let the new script 'use' the
> > subroutines stated in this subroutine-gathering
> >
> > script. I've looked at 'require' and Autoloader, but I just can't seem
to
> > find a straightforward answer to this question.
> >
> > Any of you have any idea?
>
> require does the job, just require 'subs.pl'; in the script.
>
> Read the require description in the perlfunc documentation, since there's
> an important 'must return true' bit...
>
> --
> Sam Holden
>




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

Date: 7 Jan 2003 13:15:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: using subroutines defined in other scripts
Message-Id: <avejuf$5pr$2@mamenchi.zrz.TU-Berlin.DE>

joeri <jvandervloet@hotmail.com> wrote in comp.lang.perl.misc:
> OK,
> 
> suppose this is what the subs file has:
> 
> sub pushnew (\@@) {
>     my $array = shift;
>     while (@_) {
>         push @$array, $_[0] unless grep $_[0] eq $_, @$array;
>         shift;
>     }
> }
> 1;
> 
> In a new script, I write the following:
> 
> require "c:/perl/lib/subs/perlsubs.pl";
> 
> @seen = qw/I have/;
> pushnew(@seen, "seen");
> print "@seen\n";
> 
> This should print "I have seen" normally, but it just prints "I have".
> 
> How come?

You're running without strict and warnings.  Switch them on and see
if things become clearer.

Anno


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

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


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