[21915] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4116 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 14 14:13:35 2002

Date: Wed, 13 Nov 2002 21:05:11 -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, 13 Nov 2002     Volume: 10 Number: 4116

Today's topics:
    Re: Binary Deployment for Perl? (Peter Wu)
    Re: Find perl modules in perl script (JZ)
    Re: help with arrays of arrays <nospam@rostie.net>
    Re: how do I turn off unicode on file I/O? dmeyers+perl@panix.com
    Re: how do I turn off unicode on file I/O? (Jamie Zawinski)
        How to execute a perl script from another <g0khaasa@cdf.toronto.edu>
    Re: How to execute a perl script from another <nospam@nospam.com>
    Re: How to execute a perl script from another (Tad McClellan)
    Re: How to execute a perl script from another <bwalton@rochester.rr.com>
    Re: How to execute a perl script from another <mgjv@tradingpost.com.au>
    Re: illegal use of comment ? <vm.mayer@comcast.net>
        In a Perl script executing a c-shell script to execute  (nub5)
    Re: In a Perl script executing a c-shell script to exec (Walter Roberson)
    Re: In a Perl script executing a c-shell script to exec (Vorxion)
    Re: In a Perl script executing a c-shell script to exec (Alan Barclay)
        installing perl on winxp <thebladerunner@xmission.com>
        Passing an OLE object to another OLE object (Hyer)
    Re: Perl CGI/DB advice. (sh)
    Re: Perl CGI/DB advice. <flavell@mail.cern.ch>
    Re: Perl newbie w/ code (ebchang)
    Re: Perl: string vs. numeric <derek@wedgetail.com>
        Possible solution for too long list problem requested. (Jan Fure)
        range operator w/ while operator (thomas aquinas)
    Re: range operator w/ while operator <skuo@mtwhitney.nsc.com>
    Re: range operator w/ while operator <bwalton@rochester.rr.com>
    Re: range operator w/ while operator <wksmith@optonline.net>
    Re: referening a returned array? (Vorxion)
        Setting cookie <g0khaasa@cdf.toronto.edu>
        unicode wierdness with 5.6.1/Debian woody <mike@altrion.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 13 Nov 2002 17:17:26 -0800
From: peterwu@hotmail.com (Peter Wu)
Subject: Re: Binary Deployment for Perl?
Message-Id: <9acc2ac1.0211131717.6f696b99@posting.google.com>

"Emanuel Nacht" <emanuel@xconnect.ch> wrote in message news:<3dd21e9d$1@news.swissonline.ch>...
> "Peter Wu" <peterwu@hotmail.com> wrote:
> 
> > Hello, I'm a newbie to Perl programming.
> >
> > As I am learning Perl, I find that I can run a Perl program (*.pl or
> > *.cgi) that may leverages any existing Perl Modules (*.pm).
> >
> > My question is whether we have to deploy our Perl programs to be *open
> > source*? I mean whether we can deploy a Perl prgram, at least PM, in a
> > binary format so that customers or end users will not be able to see
> > the source code I make.
> >
> > Do I have to open my source if I choose Perl to program? Thank you!
> 
> Hello Peter
> 
> you might want to take a look at activestates perl dev kit at
> http://www.activestate.com/Products/Perl_Dev_Kit/ if you're intending
> to deploy your perl programs on windows.

No, I don't want to deploy my perl programs only on Windows.
Linux/FreeBSD is my target platform. Any thoughts?


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

Date: 13 Nov 2002 18:29:26 -0800
From: ibm_97@yahoo.com (JZ)
Subject: Re: Find perl modules in perl script
Message-Id: <10bc841c.0211131829.59728d52@posting.google.com>

Thanks for all your help.

Xavier Noria <fxn@hashref.com> wrote in message news:<87smy552ju.fsf@kodo.localdomain>...
> ibm_97@yahoo.com (JZ) writes:
> 
> : Perl newbie.
> :
> : How to find installed perl modules in system (Unix or Linux) by using Perl?
> 
> If you mean you want to know whether the module Foo::Bar is installed in
> your system, see whether this gives an error (it is not) or else returns
> silently another shell prompt (it is):
> 
>     $ perl -MFoo::Bar -e1
> 
> Otherwise, if you need to list all the modules installed in your system
> try this in a sh-like shell:
> 
>     $ for d in `perl -e'print "@INC"'`; do \
>     if [ $d != '.' ]; then find $d -name '*.pm'; fi done
> 
> -- fxn


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

Date: Thu, 14 Nov 2002 03:25:36 GMT
From: Randy <nospam@rostie.net>
Subject: Re: help with arrays of arrays
Message-Id: <ae56tu4otva658ee9emdnldebfdknu7oej@4ax.com>

On 09 Nov 2002 21:31:15 -0800, Vilmos Soti <vilmos@vilmos.org> wrote:

>What about it:
>
>while (<FILE>) {
>	chomp;
>	($user, $file, $safe, $version) = split /\t/;
>	$users{$user}{file} = $file;
>	$users{$user}{safe} = $safe;
>	$users{$user}{version} = $version;
>}
>
>...
>
>foreach $user (keys %users) {
>	next if "$users{$user}{safe}" eq "yes";
>	# here comes your stuff
>}
>
>Vilmos

Here is what I am working on now,

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

my %users;

my $filename = "files.found";
open(FILE, "$filename")||die("Opening File: $!");

#store file header for later
my($hostname,$randate,$rantimestamp) = split /\t\t/, <FILE>; 
while(<FILE>){
        chomp;
        $users{$user}{file} = $file;
        $users{$user}{safe} = $safe;
        $users{$user}{version} = $version;
        my($user,$file,$safe,$version) = split /\t\t/;
}
close(FILE);
foreach $user (keys %users) {
       next if "$users{$user}{safe}" eq "yes";
print "File: $users{$user}{file}\n";
print "Safe: $users{$user}{safe}\n";
print "Version: $users{$user}{version}\n\n\n";
}

The file has 12 lines, but I just get this once:

File: 
Safe: 
Version: 



Randy


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

Date: 13 Nov 2002 18:11:59 -0500
From: dmeyers+perl@panix.com
Subject: Re: how do I turn off unicode on file I/O?
Message-Id: <yobel9poyio.fsf@panix2.panix.com>

Benjamin Goldberg <goldbb2@earthlink.net> writes:
> dmeyers+perl@panix.com wrote:
> [snip]

> > He's got 8-bit characters embedded directly in the file in
> > names of weekdays and months and such in a variety of languages.
> 
> The proper fix for this would be to alter Date/Manip.pm, and add a
> line saying 'use encoding qw(latin1);" to it.

I'll make sure to let the author know - and RedHat, since
they're including that version of Date::Manip and Perl 5.8
in their 8.0 dist.

(And make that fix in my own copy, of course!)

Hrm.  Just tried it and I still get those pesky 
 Malformed UTF-8 character (1 byte, need 4, after start byte 0xf1) at
 /path/to/lib/Date/Manip.pm line 5317.

errors.  I tried several different guesses and such
there, too, and never got it to behave differently.

> > After reading your note, though, I tossed a

> >    use open ':std', IO => ':bytes';
> 
> You don't need the ':std', unless you want to make STD{IN,OUT,ERR} into
> bytes, too.

For it to affect a module that's read in via a use Module;
doesn't it have to specifically affect STDIO, since 
'use' is effectively going to read the file through it?

> Perl source code should *NOT* have bytes with the high-bit set,
> unless there's an explicit indication of what encoding it is.  If
> there is no explicit indication, then high-bits will get interpreted
> either as bytes or as utf8 in a locale dependent way.  The open
> pragma overrides this, though.

I see.  I certainly haven't had reason to use high-bit
chars in any of my own code, but it's not too surprising
to find it in this particular module.

Thanks again.

--d

-- 


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

Date: 13 Nov 2002 17:54:02 -0800
From: jwz@jwz.org (Jamie Zawinski)
Subject: Re: how do I turn off unicode on file I/O?
Message-Id: <8ef0bdd0.0211131754.6c26b6b1@posting.google.com>

Benjamin Goldberg wrote:
> > 
> If $LANG is set to a utf-8 locale, then that is an indication, from the
> operating system, that all text files and terminal streams are in utf-8.
> 
> If the operating system is lying, that's not perl's fault.

I agree, but I want to instruct Perl to specifically ignore the OS's lie.
I expected that simply doing

    $ENV{LANG} = "C";
or
    setlocale(LC_ALL, "C");

as the first thing in my script would do that, but it doesn't.

> To tell perl to treat a filehandle as bytes, you can use:
>    binmode(FH, ":bytes");
> or:
>    binmode(FH, ":raw");
> or:
>    binmode(FH);
 ...
> In addition to using binmode, you can incorporate the file mode into the
> open statement, such as:
>    open( FH, "<:raw", $filename ) or die "Couldn't open filename: $!";
> 
> If *all* of your filehandles will be in latin1, you might want to use
> the open pragma.
> 
>    use open IO => ':bytes';

I had already tried all of these things, to no good effect.
Once I added any of the above incantations, I started always
getting two-byte characters "ö" instead of "ö" on *both*
my a.pl and b.pl scripts.

> See perldoc perllocale to see what kind of effect setlocale has.

Been there, done that, still can't make it work...

I also don't understand why, in my previous experiment, I was getting
different behavior from the a.pl and b.pl scripts -- what is different
about the environment in a.pl and b.pl that was making b.pl do what I
wanted, but making a.pl (which simply included b.pl) do something else?

My current experiements, that are still not working:

    % cat a.pl
    #!/usr/bin/perl -w

    require 5;
    use diagnostics;
    use strict;
    use bytes;

    use open ':std', IO => ':bytes';
    require 'b.pl';
    foo();

    % cat b.pl
    #!/usr/bin/perl -w

    require 5;
    use diagnostics;
    use strict;
    use bytes;

    use open ':std', IO => ':bytes';

    sub foo {
       local *IN;
       open (IN, "<:raw", "/tmp/a") || die;
       binmode(IN, ":raw");
       while (<IN>) {
         print "<<  $_";
       }
       close IN;
     }

    foo();

    1;

    % ./a.pl
    <<  foöbar
    <<  foöbar

    % ./b.pl
    <<  foöbar

    % ./a.pl | od -c
    0000000   <   <           f   o 303 266   b   a   r  \n   <   <        
    0000020   f   o 303 266   b   a   r  \n
    0000030

    % ./b.pl | od -c
    0000000   <   <           f   o 303 266   b   a   r  \n
    0000014

Any suggestions appreciated...

-- 
Jamie Zawinski      jwz@jwz.org      http://www.jwz.org/


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

Date: Wed, 13 Nov 2002 23:04:42 GMT
From: Asad <g0khaasa@cdf.toronto.edu>
Subject: How to execute a perl script from another
Message-Id: <Pine.LNX.4.30.0211131804200.3379-100000@b210-02.cdf>

How can I execute a.pl from within b.pl?



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

Date: Wed, 13 Nov 2002 15:39:53 -0800
From: "Tan D Nguyen" <nospam@nospam.com>
Subject: Re: How to execute a perl script from another
Message-Id: <aqunqh$dpold$1@ID-161864.news.dfncis.de>


"Asad" <g0khaasa@cdf.toronto.edu> wrote in message
news:Pine.LNX.4.30.0211131804200.3379-100000@b210-02.cdf...
> How can I execute a.pl from within b.pl?

perldoc -f system

system("a.pl") == ? or die "error message\n";





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

Date: Wed, 13 Nov 2002 18:20:31 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to execute a perl script from another
Message-Id: <slrnat5r2f.4n8.tadmc@magna.augustmail.com>

Asad <g0khaasa@cdf.toronto.edu> wrote:
> How can I execute a.pl from within b.pl?

   system 'a.pl';

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


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

Date: Thu, 14 Nov 2002 03:06:26 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: How to execute a perl script from another
Message-Id: <3DD31324.1050906@rochester.rr.com>

Asad wrote:

> How can I execute a.pl from within b.pl?
 ... 

Many ways:

    do 'filename.pl';
    require 'filename.pl';
    system 'filename.pl';
    exec 'filename.pl';
    `filename.pl`;

Maybe some more.  Each has its little ideosyncracies.  Read up on them 
and pick which you want to use.

-- 
Bob Walton



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

Date: Thu, 14 Nov 2002 03:18:17 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: How to execute a perl script from another
Message-Id: <slrnat65ju.2ss.mgjv@verbruggen.comdyn.com.au>

On Thu, 14 Nov 2002 03:06:26 GMT,
	Bob Walton <bwalton@rochester.rr.com> wrote:
> Asad wrote:
> 
>> How can I execute a.pl from within b.pl?
> ... 
> 
> Many ways:
> 
>     do 'filename.pl';
>     require 'filename.pl';
>     system 'filename.pl';
>     exec 'filename.pl';
>     `filename.pl`;

system 'perl', 'a.pl'; # and other variants of this

Martien
-- 
                        | 
Martien Verbruggen      | Make it idiot proof and someone will make a
Trading Post Australia  | better idiot.
                        | 


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

Date: Wed, 13 Nov 2002 22:03:20 -0500
From: Mike Mayer <vm.mayer@comcast.net>
Subject: Re: illegal use of comment ?
Message-Id: <vm.mayer-70C427.22032013112002@news-east.giganews.com>

In article <8d34tuotasptsvl7elo97a3p6aj62pb8gr@4ax.com>,
 Bart Lateur <bart.lateur@pandora.be> wrote:

> No, a liter is more like 2 pounds (actually a bit more), for water based
> fluids. One liter of pure water weighs 1 kg, and measures, in cube
> shape, 10 by 10 by 10 cm³. So 1 by 1 by 1 m³ weights1000 kg.
> Circumference of the earth is 40000km, exactly if you got the right
> direction, or the distance from equator is 10000 km. It's all
> interconnected.

Circumference of the earth is exactly 10..... 
  (if you got the right units)


=8-)


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

Date: 13 Nov 2002 15:53:31 -0800
From: rmiller_nub@yahoo.com (nub5)
Subject: In a Perl script executing a c-shell script to execute a fortran program, how to?
Message-Id: <23e193ca.0211131553.7d3eb127@posting.google.com>

Folks,
I need some help here.  I have a large fortran program that has a
c-shell script used to run it.  I have created a Perl script that
alters the input file for the fortran code and now I want to execute
the c-shell script.

Using just the script from the command line I type
% cshell_start_fortran  input_datafile

In perl I have the command
exec "cshell_start_fortran input_datafile";

It is invoking the cshell_start_fortran script but not recongnising
the input_datafile.

Any help or direction to help would be appreicated.


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

Date: 14 Nov 2002 00:30:01 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: In a Perl script executing a c-shell script to execute a fortran program, how to?
Message-Id: <aquqq9$msr$1@canopus.cc.umanitoba.ca>

In article <23e193ca.0211131553.7d3eb127@posting.google.com>,
nub5 <rmiller_nub@yahoo.com> wrote:
:I need some help here.  I have a large fortran program that has a
:c-shell script used to run it.  I have created a Perl script that
:alters the input file for the fortran code and now I want to execute
:the c-shell script.

:Using just the script from the command line I type
:% cshell_start_fortran  input_datafile

:In perl I have the command
:exec "cshell_start_fortran input_datafile";

:It is invoking the cshell_start_fortran script but not recongnising
:the input_datafile.

A) If you are writing input_datafile, are you closing the file?
(or at least flushing the buffer?)

B) In the case you show, because there are no shell metacharacters
in the string, exec should split the string up into words and pass
them as arguments to execvp(). This is going to depend upon the system
behaviour to figure out which interpreter to run, instead of upon
your starting shell (csh)'s behaviour. Does cshell_start_fortran
have a #! line that forces invocation of csh? If not then you might
find that it's being invoked under the bourne shell ('sh') instead.
--
Would you buy a used bit from this man??


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

Date: 13 Nov 2002 20:25:10 -0500
From: vorxion@fairlite.com (Vorxion)
Subject: Re: In a Perl script executing a c-shell script to execute a fortran program, how to?
Message-Id: <3dd2fb76$1_2@news.iglou.com>

In article <aquqq9$msr$1@canopus.cc.umanitoba.ca>, Walter Roberson wrote:
>In article <23e193ca.0211131553.7d3eb127@posting.google.com>,
>nub5 <rmiller_nub@yahoo.com> wrote:
>:I need some help here.  I have a large fortran program that has a
>:c-shell script used to run it.  I have created a Perl script that
>:alters the input file for the fortran code and now I want to execute
>:the c-shell script.
>
>:Using just the script from the command line I type
>:% cshell_start_fortran  input_datafile
>
>:In perl I have the command
>:exec "cshell_start_fortran input_datafile";
>
>:It is invoking the cshell_start_fortran script but not recongnising
>:the input_datafile.
>
>A) If you are writing input_datafile, are you closing the file?
>(or at least flushing the buffer?)
>
>B) In the case you show, because there are no shell metacharacters
>in the string, exec should split the string up into words and pass
>them as arguments to execvp(). This is going to depend upon the system
>behaviour to figure out which interpreter to run, instead of upon
>your starting shell (csh)'s behaviour. Does cshell_start_fortran
>have a #! line that forces invocation of csh? If not then you might
>find that it's being invoked under the bourne shell ('sh') instead.

And so long as we're at it make sure cshell_star_fortran's magic line
reads:

#!/bin/csh -f

 ...The -f prevents it from reading any user's .cshrc and thus possibly
driving something whacky.  It (-f) should generally always be used in 
both csh and tcsh scripts.

-- 
Vorxion - Member of The Vortexa Elite


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

Date: 14 Nov 2002 02:24:34 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: In a Perl script executing a c-shell script to execute a fortran program, how to?
Message-Id: <1037240673.756473@elaine.furryape.com>

In article <3dd2fb76$1_2@news.iglou.com>, Vorxion <vorxion@fairlite.com> wrote:
>In article <aquqq9$msr$1@canopus.cc.umanitoba.ca>, Walter Roberson wrote:
>#!/bin/csh -f
>
>...The -f prevents it from reading any user's .cshrc and thus possibly
>driving something whacky.  It (-f) should generally always be used in 
>both csh and tcsh scripts.

But even with -f, csh scripts can do wacky things. See 'csh programming
considered harmful' by some guy called Tom Christiansen.


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

Date: Wed, 13 Nov 2002 21:19:08 -0500
From: "thebladerunner" <thebladerunner@xmission.com>
Subject: installing perl on winxp
Message-Id: <aqv19r$phb$1@terabinaries.xmission.com>

I have a question about using perl on a winxp machine that I have at work. I
used to have a win2k machine that I was a poweruser on and this wasn't a
problem. On the new machine I am only a user. After attempting an
installation of the latest version of ActiveState Perl I cannot run any perl
scripts.  Perl does not have a proper PATH environment set-up and even if I
coax it a bit I still can't get any modules to work.

Does anyone have any advice about how to work around this problem?  I'm
about to the point of bringing my Debian laptop to work and telling my
company they can stick this XP box.

-- thebladerunner




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

Date: 13 Nov 2002 18:42:30 -0800
From: hyer_bercaw@hotmail.com (Hyer)
Subject: Passing an OLE object to another OLE object
Message-Id: <671b9222.0211131842.429c1c68@posting.google.com>

I have beat my head against the wall enough. Time to ask the experts.

I am looking a VB example and converting it to Perl. I have been able
to do everything except pass an OLE object to another OLE object. My
guess is that I have to do that by reference, but I haven't been able
to figure it out.

Here are key parts of the VB example:
Set objQuery = CreateObject("ProductStudio.Query")
Set objFields = objDataStore.FieldDefinitions
' Specify the fields to be returned
objQuery.QueryFields.Add objFields("ID")

Now in Perl:
$objQuery = Win32::OLE->new('ProductStudio.Query');
$objFields = $objDataStore->FieldDefinitions;
#Specify the fields to be returned
$objQuery->QueryFields->Add("$objFields->Item('Title')");

The last line of the Perl code returns the OLE last error of:
OLE ERROR:Win32::OLE(0.1502) error 0x80020005: "Type mismatch"
    in METHOD/PROPERTYGET "Add" argument 1

Any suggestions would be great. If I need to pass this by reference,
an example of how to do this would be even better. Thanks.


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

Date: 13 Nov 2002 15:41:47 -0800
From: phase2@phase2.net (sh)
Subject: Re: Perl CGI/DB advice.
Message-Id: <2ec67b0f.0211131541.18f4bba7@posting.google.com>

> 
> If its not, you send this password unencrypred. Just like the basic
> authentication mechanism you are trying to avoid & so you gain nothing.
> Fire you boss - she's a nitwit.
> 

Well, turns out that it is, so I'm ok on this one.  

> 
> Yes, but what about people that turn off cookies?

They're SOL. :)

Just kidding though.  I could probably do someting to test for cookies
being enabled.  If they aren't, I just won't draw the form and will
simply provide some other mechanism ( oy. ), though this might require
too much work to provide for all circumstances.

-
sh


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

Date: Thu, 14 Nov 2002 01:01:06 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Perl CGI/DB advice.
Message-Id: <Pine.LNX.4.40.0211140045360.5386-100000@lxplus033.cern.ch>

On Nov 13, sh inscribed on the eternal scroll:

> Just kidding though.  I could probably do someting to test for cookies
> being enabled.

Modern browsers offer a whole range of cookie control options, and
users could change their mind at any time.

Suppose you send your "do something to test for cookies" transaction.
The user (assuming a particular browser setting for the sake of this
example)  gets a prompt to tell them the server wants to set a cookie.
Let's suppose, for the sake of argument, that they say OK.  So your
test succeeds, and you go into the main part of your script.  Which
tries to set another cookie. and the user gets prompted again.  What
the heck, she says: wasn't one of the damned things enough for him?
So she turns them off.

Conclusion: don't try to "test" whether they have cookies enabled.
Just get on with the job, and write your code resiliently, so that it
copes sensibly with whatever happens.

One day I tried to visit a particular web site: it evidently hurled me
a cookie, and sent an HTTP redirection to the same URL, expecting to
get the cookie back again.  But I had turned them off, so it hurled me
another cookie, and redirected me again.  At that point I hadn't
realised what was going on, but I was called away to something else,
and forgot all about it, leaving my PC to go into its locked
screensaver mode; after which it was time to go home.  Next morning, I
unlocked the screensaver and found they were still at it, the remote
server having hurled many thousands of cookies, and the browser having
followed the corresponding number of redirection transactions.

atb



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

Date: Thu, 14 Nov 2002 03:55:30 GMT
From: echang@netstorm.net (ebchang)
Subject: Re: Perl newbie w/ code
Message-Id: <Xns92C5E95C7AD6Cechangnetstormnet@207.106.93.86>

Michael J Wilusz <mjwilusz@acsu.buffalo.edu> wrote in
<aqucvn$9es$1@prometheus.acsu.buffalo.edu>: 

> Hey Again,
>      Well, I took about a half hour, looked through an online Perl book
>      and 
> just wrote some preliminary code.  I took the steps Mr. Chang had given
> and broke those down (as you can see below) and tried to match code up
> to them. I must say step 4 is giving me some trouble.  I looked through
> the book, and wasn't sure exactly what to do.  I tried looking through
> a chapter on file manipulation, but it doesn't seem to have anything
> pertaining to seprating the information.  Ah well... give it a look
> over... tell me what you all think.  I know Doug (my supervisor) floats
> around in this group, so if you see this Doug, maybe you can point me
> to the right chapter or such.  Have a good day all!
> 
> 1.  print the heading;
> 
> print "     Phone Book\n"; #prints "Phone Book" followed by a new line
> print "Name       Phone Number";
> 
> 2.  open the file (look up open in
> the the text and also read the perlopentut documentation);
> 
> chdir ("/ubfs/shared/cit/HelpDesk/Ushsoft/databases"); #Switches to
> directory of the names.dat
> $file="names.dat"; #opens the names.dat

Nope, this assigns the file name to a variable named $file.

> 3.  read the lines
> from the file (probably the same chapter in the text);
> 
> open (DATFILE, "names.dat"); #opens the names.dat and sets as type
> DATFILE 

This is the one that opens it for reading, associating it with the 
filehandle DATAFILE.  You could also have done open (DATAFILE, $file) since 
you have the file name in a variable.  

Others have mentioned a number of precautions (warnings, strict, testing the 
result of open) that are good advice.  You'll need to read further in your 
sources to understand them.

Speaking of reading, you haven't mentioned which book you are making use of.  
If you identify it, we may be able to point you to specific sections.

Absent that, there's a tutorial at http://www.sthomas.net/roberts-perl-
tutorial.htm.  It has sections on reading from files and the split function, 
(which is what you need for item 4)  

 
> 4.  split each line into a list of the separate fields
> 
> 5.  print out the designated fields

After you split, the fields will be the elements of an array, so you will 
need to read up on arrays as well.
 
> 6.  making the necessary adjustment to the phone number

5 and 6 were originally a single sentence; separating them changes the 
meaning. As David K. Wall noted, you have to make the adjustments before 
printing, not after.  Look into the tr function for replacing one character 
with another. 
 
> 8.  close the file

Just think what you might manage with a couple of hours of reading. :-)

-- 
EBC


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

Date: Thu, 14 Nov 2002 00:41:44 GMT
From: Derek Thomson <derek@wedgetail.com>
Subject: Re: Perl: string vs. numeric
Message-Id: <cjCA9.95$ri6.2512@news.optus.net.au>

Daniel Pfeiffer wrote:
> Derek Thomson <derek@wedgetail.com> skribis:
> 
>>If you want the subroutine to try to detect if the argument is not a 
>>number, and then quote it, you'll find ways to do this in the Perl 
>>documentation that you already have.
> 
> 
> Does it?  

It's in the Perl FAQ part 4:

"How do I determine whether a scalar is a num­ber/whole/integer/float?"

--
D.



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

Date: 13 Nov 2002 18:17:46 -0800
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Possible solution for too long list problem requested.
Message-Id: <e47a84bf.0211131817.4e8b0bef@posting.google.com>

I recently wrote a script which requires user input to pick a
directory in which to process files. The way to pick one or more
directories is by inputing a matching string through standard input.

The problem with my script is that if @dirs contains more elements
than can be displayed on the output terminal (~25-50), the user will
be required to scroll back (may or may not work depending on terminal
definition) or know in advance which directory to choose based on
looking at the directory list.

The ideal solution would be some output similar to lynx (the original
web browser) where the user can browse through the @dirs elements and
pick one or more elements. Another solution would be using the
WIN32::GUI module, and create a dialog where the user picks one or
more elements.

I don't know how to do either, but would be grateful for any
suggestions.

Jan Fure

The data selection part of the code is included below:

foreach (@dirs) {
    	print("$_\n");
	}
print "Type in a unique string matching desired directory name: \n";
my $name_subset = <STDIN>; #allow user to type a unique subset of full
name
chop($name_subset);


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

Date: 14 Nov 2002 01:43:30 GMT
From: aquinas@no.uce.thanks.com (thomas aquinas)
Subject: range operator w/ while operator
Message-Id: <aquv41$e062f$1@ID-42081.news.dfncis.de>

Hi all,

How can this command line sequence be expressed in a while loop?

    $ perl -ne 'print if /^Received/ .. /\d\d\d\d$/' /some/mail/spool

Here what I tried:

--

  open(SPOOL, $spool) || die "could not open $spool: $!";

      while (<SPOOL>)
      {
          print if /^Received/ .. /\d\d\d\d$/      
      }
      close SPOOL;     

--

Which fails with:

     Modification of a read-only value attempted at script line 2 

Why, and what is a right way to do it?

Thanks,
thomas



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

Date: Wed, 13 Nov 2002 18:17:35 -0800
From: Steven Kuo <skuo@mtwhitney.nsc.com>
Subject: Re: range operator w/ while operator
Message-Id: <Pine.GSO.4.21.0211131813400.14186-100000@mtwhitney.nsc.com>

On 14 Nov 2002, thomas aquinas wrote:

> Hi all,
> 
> How can this command line sequence be expressed in a while loop?
> 
>     $ perl -ne 'print if /^Received/ .. /\d\d\d\d$/' /some/mail/spool



Well, you could always ask perl itself:

% perl -MO=Deparse -ne 'print if /^Received/ .. /\d\d\d\d$/'
LINE: while (defined($_ = <ARGV>)) {
    print $_ if /^Received/ .. /\d\d\d\d$/;
}
-e syntax OK




> Here what I tried:
> 
> --
> 
>   open(SPOOL, $spool) || die "could not open $spool: $!";
> 
>       while (<SPOOL>)
>       {
>           print if /^Received/ .. /\d\d\d\d$/      
>       }
>       close SPOOL;     
> 
> --
> 
> Which fails with:
> 
>      Modification of a read-only value attempted at script line 2 
> 
> Why, and what is a right way to do it?
> 
> Thanks,
> thomas


 
That section of code compiles cleanly on my machine; your problem is
likely elsewhere.   Post the entire program (if it's short).

-- 
HTH,
Steven



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

Date: Thu, 14 Nov 2002 02:58:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: range operator w/ while operator
Message-Id: <3DD31134.1080108@rochester.rr.com>

thomas aquinas wrote:

> Hi all,
> 
> How can this command line sequence be expressed in a while loop?
> 
>     $ perl -ne 'print if /^Received/ .. /\d\d\d\d$/' /some/mail/spool


Thanks to the -n, that code *is* in a while loop.


> 
> Here what I tried:
> 
> --
> 
>   open(SPOOL, $spool) || die "could not open $spool: $!";
> 
>       while (<SPOOL>)
>       {
>           print if /^Received/ .. /\d\d\d\d$/      
>       }
>       close SPOOL;     
> 
> --
> 
> Which fails with:
> 
>      Modification of a read-only value attempted at script line 2 
> 
> Why, and what is a right way to do it?
> 
> Thanks,
> thomas
> 
> 

Well, the following similar code:

  while (<DATA>)
       {
           print if /^Received/ .. /\d\d\d\d$/
       }
__END__
line 1
Received some junk
blah
line 4
blah blah
blah 4567
line 7
line 8

works fine.  Since line 2 of your stated program is blank, your error 
message must have come from some code other than what you posted.  Try 
to narrow your problem down to a small standalone piece of code that 
anyone can cut/paste/execute, like the above, and perhaps we can be of 
more help.

-- 
Bob Walton



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

Date: Thu, 14 Nov 2002 04:16:30 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: range operator w/ while operator
Message-Id: <ysFA9.26621$Vy4.25115@news4.srv.hcvlny.cv.net>


"thomas aquinas" <aquinas@no.uce.thanks.com> wrote in message
news:aquv41$e062f$1@ID-42081.news.dfncis.de...
> Hi all,
>
> How can this command line sequence be expressed in a while loop?
>
>     $ perl -ne 'print if /^Received/ .. /\d\d\d\d$/' /some/mail/spool
>

Your print statement is already assumed to be in a while loop.  Refer
perldoc perlrun for description of switch -n.



> Here what I tried:
>
> --
>
>   open(SPOOL, $spool) || die "could not open $spool: $!";
>
>       while (<SPOOL>)
>       {
>           print if /^Received/ .. /\d\d\d\d$/
>       }
>       close SPOOL;
>
> --
>
> Which fails with:
>
>      Modification of a read-only value attempted at script line 2

Clearly you did not have the lines

use strict;
use warnings;

as lines 1 and 2.  That should be the first step in debugging any Perl
problem even though it probably would not have helped in this case.

>
> Why, and what is a right way to do it?

You have the right idea.  Are you sure that this is the code that failed?

Bill




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

Date: 13 Nov 2002 20:22:26 -0500
From: vorxion@fairlite.com (Vorxion)
Subject: Re: referening a returned array?
Message-Id: <3dd2fad2$1_2@news.iglou.com>

In article <1037147993.401762@elaine.furryape.com>, Alan Barclay wrote:
>In article <3dd18ef5$1_2@news.iglou.com>, Vorxion <vorxion@fairlite.com> wrote:
>>...And this yields:
>>
>>ARRAY(0x34078c)
>>
>>Someone care to tell me how to get INTO that array?  Please?
>
>You have a reference to the array. Use
>
>$body = $top->body;
>foreach(@{$body){ print; }

I think you mean:

foreach(@{${body}}){print;}

Yes?  Yes, it just worked.  you missed a brace.

I'd tried @$body but probably needed the braces for the array segment.  I
use braces in all rvalue variables out of convention.  Ah, and I was also
assigning into @body, not $body.  Thanks for the pointer.

>and check 'perldoc perlref' and 'perldoc perlreftut'

I'm familiar with some of the references, like when using Getopt::Long for
instance, or passing filehandles, but yes, I need to brush up on the 
references.  Thanks for the answer and the tip!

-- 
Vorxion - Member of The Vortexa Elite


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

Date: Thu, 14 Nov 2002 02:42:14 GMT
From: Asad <g0khaasa@cdf.toronto.edu>
Subject: Setting cookie
Message-Id: <Pine.LNX.4.30.0211132142060.5378-100000@b210-02.cdf>

Hi!

I have the following sub-routine in my addToCart.pl file:

sub print_page_start {
        if ($session_id) {
                my $cookie = $query->cookie(-name=>'session_id',
-value=>$session_id);
                print $query->header(-cookie=>$cookie);
        }
        else {
                print $query->header;
        }
        print "<html>\n<head></head>\n";
        print "<body>\n";
}

However, it is totally goofing up and writing out the cookie information
out to my html file. It appears on the page that is. However, when I view
source, the cookie information appears right at the end, even after the
</html> tag.

BTW, I did need it to redisplay the same page (by calling another perl
function) so I inlcuded this line on top of my perl script:

require ("fetchMovies.pl") || die ("Can't find fetchMovies.pl\n");

and somehow it miracilously reloads the page :s

Lil help.




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

Date: Wed, 13 Nov 2002 23:43:33 +0000
From: Mike Whitaker <mike@altrion.org>
Subject: unicode wierdness with 5.6.1/Debian woody
Message-Id: <aquo2n$dj48u$1@ID-133847.news.dfncis.de>

The following code snippet (in a mod_perl handler) dies on me for *certain* 
input only:

<from AdLib::CGI::Insert.pm>

sub score_match {
    my $match = shift;
    my $what = shift;
    my $matchscore = shift;
    my $failscore = shift;
    my $test;
    chomp $what;
    $match =~ s/\s+//;

    if ($match =~ s/^\!//)
    {
        $test = !($what =~ /$match/);
    }
    else
    {
        $test = ($what =~ /$match/);
    }

    return $test ? $matchscore : $failscore;
}

The error trace in the failure case is:

Uncaught exception from user code:
        Can't find unicode character property definition via main->A or A.pl 
at unicode/Is/A.pl line 0
        Carp::croak('Can\'t find unicode character property definition via 
main->A or...') called at /usr/share/perl/5.6.1/utf8_heavy.pl line 8
        utf8::croak('Can\'t find unicode character property definition via 
main->A or...') called at /usr/share/perl/5.6.1/utf8_heavy.pl line 30
        utf8::SWASHNEW('utf8', 'A', '', 0, 0, 0) called at 
/usr/share/perl/5.6.1/utf8_heavy.pl line 78
        utf8::SWASHNEW('utf8', '', '# comment^J!utf8::A^J', 1, 0) called at 
unicode/Is/A.pl line 0
        
AdLib::CGI::Insert::score_match('^\/index.html$|^\/link_to_database\/NATIONAL\/IND\/index.html$|^...', 
'/index.html', 200, -1000000) called at /usr/lib/perl5/AdLib/CGI/Insert.pm 
line 296
        AdLib::CGI::Insert::score_path('AdLib::Advert=HASH(0x850fb7c)', 400) 
called at /usr/lib/perl5/AdLib/Server.pm line 382
        AdLib::Server::choose('AdLib::Server=HASH(0x844e3c4)', 'content', '') 
called at /usr/lib/perl5/AdLib/CGI/Insert.pm line 499
        AdLib::CGI::Insert::handler('Apache=SCALAR(0x843f494)') called at 
unicode/Is/A.pl line 0
        eval {...}

I'm stumped. Anyone know what's going on here?
-- 
Mike Whitaker    | Tel: +44 1733 327545 | Work: mike@cricinfo.com
System Architect | Fax: +44 1733 571960 | Home: mike@altrion.org
CricInfo Ltd     | GSM: +44 7971 977375 | Web: http://www.cricinfo.com/


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

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


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