[17167] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4579 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 11 03:05:49 2000

Date: Wed, 11 Oct 2000 00:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971247914-v9-i4579@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 11 Oct 2000     Volume: 9 Number: 4579

Today's topics:
        Convert array to string? <cyberman@NO-SPAMtamu.edu>
    Re: Convert array to string? (Rafael Garcia-Suarez)
        Help with arrat of references <kroot@eddy.nto.telecom.com.au>
    Re: Help with arrat of references (Martien Verbruggen)
        How to Print the Next Line Following a Pattern <luckyq@angelfire.com>
    Re: How to Print the Next Line Following a Pattern <jeffp@crusoe.net>
    Re: how to remove unprintable  chars with Perl script <krahnj@acm.org>
    Re: how to remove unprintable  chars with Perl script <lr@hpl.hp.com>
    Re: http_cookie not set in ms ie <elephant@squirrelgroup.com>
    Re: http_cookie not set in ms ie <troyr@vicnet.net.au>
    Re: included files: missing one important concept... <mcdonabNO@SPAMyahoo.com>
    Re: included files: missing one important concept... (Martien Verbruggen)
    Re: included files: missing one important concept... <mcdonabNO@SPAMyahoo.com>
    Re: included files: missing one important concept... <korthner@hotmail.nospam.com>
    Re: included files: missing one important concept... (Martien Verbruggen)
    Re: included files: missing one important concept... <mcdonabNO@SPAMyahoo.com>
    Re: included files: missing one important concept... <mcdonabNO@SPAMyahoo.com>
    Re: included files: really confused, and perldoc doesn' <jeff@vpservices.com>
    Re: included files: really confused, and perldoc doesn' <mcdonabNO@SPAMyahoo.com>
        Is perl object oriented? <mark@mediamasters.net>
        MacPerl's unlink: Where do files go? juump@my-deja.com
    Re: newbie: pws and active perl <elephant@squirrelgroup.com>
        OPEN file efficiancy issue, <webmaster@ostas.lu.se>
    Re: OPEN file efficiancy issue, <godzilla@stomp.stomp.tokyo>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Oct 2000 01:17:11 -0500
From: "Michael" <cyberman@NO-SPAMtamu.edu>
Subject: Convert array to string?
Message-Id: <8s10m3$o3q$1@news.tamu.edu>

Is is possible to convert an array of characters to a string. I know this is
possible in java via typecast. But I am not able to find anyting in any book
on how to do it in perl.  Does anybody know if this is possible?  If so how
might I go about doing this?

thanx
-mike




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

Date: Wed, 11 Oct 2000 06:57:01 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Convert array to string?
Message-Id: <slrn8u846u.hkt.rgarciasuarez@rafael.kazibao.net>

Michael wrote in comp.lang.perl.misc:
>Is is possible to convert an array of characters to a string. I know this is
>possible in java via typecast. But I am not able to find anyting in any book
>on how to do it in perl.  Does anybody know if this is possible?  If so how
>might I go about doing this?

Apparently you don't think in Perl yet.

  $string = join '' => @array;

BTW, array of characters don't exist in perl, because there's no
datatype for characters.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Wed, 11 Oct 2000 15:40:10 +1100
From: Andy Lee <kroot@eddy.nto.telecom.com.au>
Subject: Help with arrat of references
Message-Id: <39E3EF29.E20ABFAD@eddy.nto.telecom.com.au>

Peoples,
    I have a list of names that I want to use to refer to hashes, ie


@switches = ("vrcno675","vrcno714");   # The list.......

# the hashes......

%vrcno714 = { "Interface Serial 1/0" => "1.3.6.1.2.1.2.2.1.7.3",
                "Interface Serial 2/0" => "1.3.6.1.2.1.2.2.1.7.7"
                };

%vrcno675 = { "Interface Serial 1/2" => "1.3.6.1.2.1.2.2.1.7.5",
                "Interface Serial 2/2" => "1.3.6.1.2.1.2.2.1.7.9"
                };

for each element in the list @switches I want to work with the
corresponding hash

ie
foreach (@switches)
{
my sw = $_;
while (( $key , $value ) = each (%sw)
    {
    do something;
    }
}

    The problem is obviously trying to reference the hash %sw, what am I

doing wrong.........


TIA




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

Date: Wed, 11 Oct 2000 05:29:54 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Help with arrat of references
Message-Id: <slrn8u7um8.8q8.mgjv@verbruggen.comdyn.com.au>

On Wed, 11 Oct 2000 15:40:10 +1100,
    Andy Lee <kroot@eddy.nto.telecom.com.au> wrote:
> Peoples,
>     I have a list of names that I want to use to refer to hashes, ie
> 
> 
> @switches = ("vrcno675","vrcno714");   # The list.......
> 
> # the hashes......
> 
> %vrcno714 = { "Interface Serial 1/0" => "1.3.6.1.2.1.2.2.1.7.3",
>                 "Interface Serial 2/0" => "1.3.6.1.2.1.2.2.1.7.7"
>                 };
> 
> %vrcno675 = { "Interface Serial 1/2" => "1.3.6.1.2.1.2.2.1.7.5",
>                 "Interface Serial 2/2" => "1.3.6.1.2.1.2.2.1.7.9"
>                 };

That's incorrect. Should give a warning. Use () instead of the
curlies.

> for each element in the list @switches I want to work with the
> corresponding hash
> 
> ie
> foreach (@switches)
> {
> my sw = $_;
> while (( $key , $value ) = each (%sw)
>     {
>     do something;
>     }
> }

You are asking about symbolic references:

foreach my $sw (@switches)
{
    while (my ($key, $value) = each %{$sw})
    {
        print "$sw: $key -> $value\n";
    }
}

# perldoc perlref

BUT YOU DO NOT WANT TO DO THIS.

Sorry for shouting, but this question comes up at least once a week on
this group. You should read

# perldoc perlref
# perldoc perllol
# perldoc perldsc

and the FAQ entries

# perldoc perlfaq7
[snip]
       How can I use a variable as a variable name?
[snip]


You really do not want to do this. What you want to do instead, is use
strict, -w, and read the perllol and perldsc documentation. because
you want a slightly more complex data structure, but it will make your
life so much easier.

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

my %switches = (

    vrcno714 => { 
        "Interface Serial 1/0" => "1.3.6.1.2.1.2.2.1.7.3",
        "Interface Serial 2/0" => "1.3.6.1.2.1.2.2.1.7.7"
    },

    vrcno675 => { 
        "Interface Serial 1/2" => "1.3.6.1.2.1.2.2.1.7.5",
        "Interface Serial 2/2" => "1.3.6.1.2.1.2.2.1.7.9"
    },
);

foreach my $sw (keys %switches)
{
    while (my ($key, $value) = each %{$switches{$sw}})
    {
        print "$sw: $key -> $value\n";
    }
}


Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | The world is complex; sendmail.cf
Commercial Dynamics Pty. Ltd.   | reflects this.
NSW, Australia                  | 


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

Date: Tue, 10 Oct 2000 23:14:07 -0500
From: "Luck E. Q." <luckyq@angelfire.com>
Subject: How to Print the Next Line Following a Pattern
Message-Id: <39E3E90F.2DBAF989@angelfire.com>

How do I print the next line (or row) following a successful match in a
pattern search?

Sample code:
____________
#!/usr/local/bin/perl
# Read from standard input
$first=1;
$line=-1;
while (<STDIN>) {
        chop;
       #In case first line is blank...
        if ($first) {
                $first=0;
                next unless ($_);
        }
        $line++;
             if (!$headers_found) {
                # Check for pattern match on FLAG:
                if (/FLAG: [\t ]*(.*)/i) {
                <print the next row from STDIN and exit loop>
;                           

Sample Data:
____________
blah blah
blah
FLAG:
 super-blah
blah blah blah
blah blah


I want to read in a file and print "super-blah" as the output.
"super-blah" may appear anywhere in the file but I only want to print
the occurrence after "FLAG:".

Thank you.


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

Date: Wed, 11 Oct 2000 00:37:20 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: How to Print the Next Line Following a Pattern
Message-Id: <Pine.GSO.4.21.0010110035370.14163-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 10, Luck E. Q. said:

>How do I print the next line (or row) following a successful match in a
>pattern search?

  if ($current_line =~ /pattern/) {
    $next_line = <FILE>;
    # do whatever with $next_line
  }

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 10 Oct 2000 22:43:22 -0700
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to remove unprintable  chars with Perl script
Message-Id: <39E3FDFA.9D97C2B8@acm.org>

Larry Rosler wrote:
> 
> In article <39E25037.EEDA60FB@acm.org> on Mon, 09 Oct 2000 16:09:43 -
> 0700, John W. Krahn <krahnj@acm.org> says...
> > This should work:
> >
> > s/[:^print:]//g;
> 
> Perhaps you think it 'should work', but it doesn't (it needs another set
> of square brackets), as you could have found out trivially by trying it
> before posting it, or even by checking it out in perlre.
> 
>   This should work:
> 
>   s/[[:^print:]]//g;

Oops, sorry, I tested with 'perl -cw' and 'use strict' but didn't
actually test it on a string. I looked through perlre and perlop and
grepped the 5.6.0 source tree and the only references I found were in
regcomp.c, t/op/re-tests, and ext/re/re_comp.c which weren't very
helpful.

> The POSIX 'print' class includes the four whitespace control characters
> "\t" "\n" "\f" "\r", which is different from the C isprint() class.

From ISALPHA(3) man page:

       isprint()
              checks for any printable character including space.

       isspace()
              checks for white-space characters.  In the "C"  and
              "POSIX"   locales,   these  are:  space,  form-feed
              ('\f'), newline  ('\n'),  carriage  return  ('\r'),
              horizontal tab ('\t'), and vertical tab ('\v').



> If locale-dependent issues aren't involved, then the following is much
> faster.  The four whitespace control characters can be included if
> desired:
> 
>   tr/\x20-\x7e//cd;
> 
> Or, to save keystrokes,
> 
>   tr/ -~//cd;

Agreed.

John


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

Date: Tue, 10 Oct 2000 23:50:40 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: how to remove unprintable  chars with Perl script
Message-Id: <MPG.144dad971d46582898ae22@nntp.hpl.hp.com>

In article <39E3FDFA.9D97C2B8@acm.org>, krahnj@acm.org says...
> Larry Rosler wrote:
> > In article <39E25037.EEDA60FB@acm.org> on Mon, 09 Oct 2000 16:09:43 -
> > 0700, John W. Krahn <krahnj@acm.org> says...
> > > This should work:
> > >
> > > s/[:^print:]//g;
> > 
> > Perhaps you think it 'should work', but it doesn't (it needs another set
> > of square brackets), as you could have found out trivially by trying it
> > before posting it, or even by checking it out in perlre.
> > 
> >   This should work:
> > 
> >   s/[[:^print:]]//g;
> 
> Oops, sorry, I tested with 'perl -cw' and 'use strict' but didn't
> actually test it on a string.

Gasp!  Testing on data is the 'acid test' (a term which predates 
database theory :-).

>                                I looked through perlre and perlop and
> grepped the 5.6.0 source tree and the only references I found were in
> regcomp.c, t/op/re-tests, and ext/re/re_comp.c which weren't very
> helpful.

From perlre:

  For example use [:upper:] to match all the uppercase characters. Note
  that the [] are part of the [::] construct, not part
  of the whole character class. For example:

      [01[:alpha:]%]

  matches one, zero, any alphabetic character, and the percentage sign.

Despite its apparent popularity hereabouts, 'Perl source' ne 'Perl 
documentation'.

> > The POSIX 'print' class includes the four whitespace control characters
> > "\t" "\n" "\f" "\r", which is different from the C isprint() class.
> 
> From ISALPHA(3) man page:
> 
>        isprint()
>               checks for any printable character including space.

In that definition, 'space' means " " ("\x20").  It is added to the 
definition to distinguish isprint() from isgraph(), which starts at 
"\x21".

>        isspace()
>               checks for white-space characters.  In the "C"  and
>               "POSIX"   locales,   these  are:  space,  form-feed
>               ('\f'), newline  ('\n'),  carriage  return  ('\r'),
>               horizontal tab ('\t'), and vertical tab ('\v').

So that definition is irrelevant.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 11 Oct 2000 15:07:36 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: http_cookie not set in ms ie
Message-Id: <MPG.144ea0a6c2423f8598980b@localhost>

klooser@tech.ch wrote ..
>i get some problems with micorsoft IE. it's not possible to read the
>cookie. The Browser set's the cokkie with correct values.then i tried
>to receive the cookie with fetch CGI::Cookie.
>http_cookie ENV is not set by using ms IE.
>
>With netscape everything work fine.
>
>use: apache 1.3.9 unix, perl 5.005_03, solaris 2.6
>
>any idea?

if your cookies work with one browser but not with another browser - 
then the problem is not a Perl problem .. perhaps find out how IE 
handles cookies from Microsoft or a related newsgroup/FAQ/website/etc.

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Wed, 11 Oct 2000 15:42:09 +1100
From: "Troy Rasiah" <troyr@vicnet.net.au>
Subject: Re: http_cookie not set in ms ie
Message-Id: <_cSE5.25142$O7.393909@ozemail.com.au>

> >i get some problems with micorsoft IE. it's not possible to read the
> >cookie. The Browser set's the cokkie with correct values.then i tried
> >to receive the cookie with fetch CGI::Cookie.
> >http_cookie ENV is not set by using ms IE.
> >
> >With netscape everything work fine.
> >
> >use: apache 1.3.9 unix, perl 5.005_03, solaris 2.6
> >
> >any idea?
>
> if your cookies work with one browser but not with another browser -
> then the problem is not a Perl problem .. perhaps find out how IE
> handles cookies from Microsoft or a related newsgroup/FAQ/website/etc.
>
> --
>   jason -- elephant@squirrelgroup.com --

I had the same problem....seems to work fine with IE up till 5.5
5.0 and under work fine

Troy




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

Date: Tue, 10 Oct 2000 21:13:03 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: included files: missing one important concept...
Message-Id: <UNRE5.206$6I3.148933@news.pacbell.net>

Hi. I believe that I am something of a dunce here. I've read perlfunc...
perlfaq8... perlmod; I've combed through HUNDREDS of posts at deja; I've
read dozens of replies to my (same) question, where the perl intelligentsia
say "check perldoc do;perldoc require;perldoc use"... as if that is all that
is needed for comprehension; I've seen many posters driven into the ground
for asking this very question.

And my post is sitting here... unresponded to... perhaps laughed at... (or
silently and universally mocked???)

But, when it is all said and done, I still don't understand how to include a
file with variable definitions and initializations in a Perl script.

I hope that someone can help me. I know that the answer is probably
something simple. It will probably make me feel (more) inane. But... I am
new to Perl... and I've spent over half a day... and I hope that counts for
something.

Brian

"Brian McDonald" <mcdonabNO@SPAMyahoo.com> wrote in message
news:y9PE5.4889$Wq1.1799186@nnrp5-w.sbc.net...
> Hi again.
>
> I believe that I am missing one important concept that will enable me to
> proceed.
>
> I have created a module called, datadefs.pm, that I want to include in my
> script txt2xml.pl. It goes something like this...
>
> datadefs.pm:
> ----
>
> my $roottag  = "<lsdml>";
> my $rootetag = "</lsdml>";
>
> # LSDml child start tags
> my @lsdml_child_st = qw( <Document> );
>
> # LSDml child end tags
> my @lsdml_child_et = qw( </Document> );
>
> (plus a whole lotta other defs...)
>
> ----
>
> In txt2xml.pl I have...
>
> ----
>
> #!\usr\bin\perl -w
> use strict;
> use DBI;
> use datadefs;
>
> (plus a whole lotta logic...)
>
> ----
>
> The problem is that when I compile this I get the following errors (which
> another poster once posted... but got no response!):
>
> Global symbol "$roottag" requires explicit package name at txt2xml.pl line
> 75
> Global symbol "@lsdml_child_et" requires explicit package name at
txt2xml.pl
> line 87
> Global symbol "@rootetag" requires explicit package name at txt2xml.pl
line
> 88
>
> Do I have to preface each variable in txt2xml.pl with something like
> 'Package::' in order that the variable is understood?
>
> Something else?
>
> Thanks,
> Brian




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

Date: Wed, 11 Oct 2000 04:34:36 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: included files: missing one important concept...
Message-Id: <slrn8u7rei.8q8.mgjv@verbruggen.comdyn.com.au>

On Tue, 10 Oct 2000 18:13:27 -0700,
	Brian McDonald <mcdonabNO@SPAMyahoo.com> wrote:
> Hi again.
> 
> I believe that I am missing one important concept that will enable me to
> proceed.
> 
> I have created a module called, datadefs.pm, that I want to include in my
> script txt2xml.pl. It goes something like this...
> 
> datadefs.pm:
> ----
> 
> my $roottag  = "<lsdml>";
> my $rootetag = "</lsdml>";

# perldoc -f my

> 
> # LSD

       my EXPR : ATTRIBUTES
               A `my' declares the listed variables to be local
               (lexically) to the enclosing block, file, or
               `eval'.

Note 'file' and 'eval'.

This means that those variables will not be accessible anywhere
outside of that file. Not even after a do, require, use or eval.

To do what you want, you will have to allow global variables in your
program.

# cat datadefs.pm
$roottag  = "<lsdml>";
$rootetag = "</lsdml>";
# cat proggie
#!/usr/local/bin/perl -w
use strict;
use vars qw($roottag $rootetag);
require 'datadefs.pm';
print "$roottag\n";
# ./proggie
<lsdml>
#

> Do I have to preface each variable in txt2xml.pl with something like
> 'Package::' in order that the variable is understood?

No, and yes. Depends. You create a file with a pm extension. normally
those are perl _modules_. Perl modules generally a libraries that
contain everything specific to a package.

I probably would think that what you're trying to do is probably not
the cleanest way to do whatever you are trying to do.

What _are_ you trying to do? In words? What's the purpose of this
file? Configuration information for multiple different modules? or
programs? Maybe you should create a real module, and provide accessors
for your information? maybe you should create a module and export
things? Maybe, if they're just constants, you need to think about
using the constant pragma:

# cat datadefs.pm
use constant FOO => "banana";
# cat proggie
#!/usr/local/bin/perl -w
use strict;
require 'datadefs.pm';
print FOO()."\n";
# ./proggie
banana
#

It's hard to tell what the best solution is, because we don't know
what the problem is. You tell us your problem is that you can't use
lexical variables in an included file, and make those available to the
main program. That's however not the problem, that's a symptom of the
wrong implementation of whatever your real problem is.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Tue, 10 Oct 2000 22:15:00 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: included files: missing one important concept...
Message-Id: <ZHSE5.212$6I3.164198@news.pacbell.net>

Thanks Martien....

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8u7rei.8q8.mgjv@verbruggen.comdyn.com.au...
> On Tue, 10 Oct 2000 18:13:27 -0700,
> Brian McDonald <mcdonabNO@SPAMyahoo.com> wrote:
> # perldoc -f my
>

Just a comment: I am, in fact, using ActiveState. Am I right in concluding
that there is no perldoc utility in this Windows port? (I've searched the
faqs previously for info on this, but turned up nothing.) Often I have to
dig blindly in the ActiveState docs in order to find the information that
posters in this newsgroup are referring to.

> >
> > # LSD
>
>        my EXPR : ATTRIBUTES
>                A `my' declares the listed variables to be local
>                (lexically) to the enclosing block, file, or
>                `eval'.
>
> Note 'file' and 'eval'.
>
> This means that those variables will not be accessible anywhere
> outside of that file. Not even after a do, require, use or eval.
>

Ok. I didn't even realize that this was a problem. I should have... but
didn't.

> To do what you want, you will have to allow global variables in your
> program.
>
> # cat datadefs.pm
> $roottag  = "<lsdml>";
> $rootetag = "</lsdml>";
> # cat proggie
> #!/usr/local/bin/perl -w
> use strict;
> use vars qw($roottag $rootetag);
> require 'datadefs.pm';
> print "$roottag\n";
> # ./proggie
> <lsdml>
> #
>

Here I am starting to sense that I have miscommunicated my intentions. (And
this anticipates your impending question: "What are you trying to do?")

The file that I've called 'datadefs.pm' is huge. It has many variables
defined and initialized. It defines some data structures as well. I
definitely wouldn't want to have to create a qw-array of them in the
including script as you've done with...

use vars qw($roottag $rootetag);

At least I don't think I would.

> > Do I have to preface each variable in txt2xml.pl with something like
> > 'Package::' in order that the variable is understood?
>
> No, and yes. Depends. You create a file with a pm extension. normally
> those are perl _modules_. Perl modules generally a libraries that
> contain everything specific to a package.
>
> I probably would think that what you're trying to do is probably not
> the cleanest way to do whatever you are trying to do.
>
> What _are_ you trying to do? In words? What's the purpose of this
> file? Configuration information for multiple different modules? or
> programs? Maybe you should create a real module, and provide accessors
> for your information? maybe you should create a module and export
> things? Maybe, if they're just constants, you need to think about
> using the constant pragma:
>

I am writing a text-to-XML parser that operates on a CSV raw data file. As
such, I have nearly 530 lines of variable definitions/initializations...
defining tags, attributes and data structures. I would simply like to move
them into another file and include them back into my Perl script,
txt2xml.pl.

So, really, I don't think that what I'm doing requires that I create a Perl
Module. But, I was doing that because those were the only examples that
seemed to come close to the thing I was trying to do.

I was surprised that this was the case, but it was the case nonetheless.

If not a module, what?


> # cat datadefs.pm
> use constant FOO => "banana";
> # cat proggie
> #!/usr/local/bin/perl -w
> use strict;
> require 'datadefs.pm';
> print FOO()."\n";
> # ./proggie
> banana
> #
>
> It's hard to tell what the best solution is, because we don't know
> what the problem is. You tell us your problem is that you can't use
> lexical variables in an included file, and make those available to the
> main program. That's however not the problem, that's a symptom of the
> wrong implementation of whatever your real problem is.
>
> Martien





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

Date: 11 Oct 2000 14:47:04 +0900
From: Kent Orthner <korthner@hotmail.nospam.com>
Subject: Re: included files: missing one important concept...
Message-Id: <wkbswsvsiv.fsf@hotmail.nospam.com>

Hi, Brian.

I just checked, and it works fine for me, using Build 522 from
ActiveState.  Perldoc.bat is in the Perl/bin (will I get flamed
for writing "perl/bin", or "PERL/BIN"?) subdirectory.  If you have
your PATH set to include Perl/bin, you should be fine.

-Kent


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

Date: Wed, 11 Oct 2000 06:07:08 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: included files: missing one important concept...
Message-Id: <slrn8u80s3.8q8.mgjv@verbruggen.comdyn.com.au>

On Tue, 10 Oct 2000 22:15:00 -0700,
	Brian McDonald <mcdonabNO@SPAMyahoo.com> wrote:
> Thanks Martien....
> 
> "Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
> news:slrn8u7rei.8q8.mgjv@verbruggen.comdyn.com.au...
> > On Tue, 10 Oct 2000 18:13:27 -0700,
> > Brian McDonald <mcdonabNO@SPAMyahoo.com> wrote:
> > # perldoc -f my
> >
> 
> Just a comment: I am, in fact, using ActiveState. Am I right in concluding
> that there is no perldoc utility in this Windows port? (I've searched the
> faqs previously for info on this, but turned up nothing.) Often I have to
> dig blindly in the ActiveState docs in order to find the information that
> posters in this newsgroup are referring to.

Nope, you are not right :) ActiveState's Perls all come with perldoc.
Maybe you should check that your path is set up correctly? I don't
know that much about win32.

> >        my EXPR : ATTRIBUTES
> >                A `my' declares the listed variables to be local
> >                (lexically) to the enclosing block, file, or
> >                `eval'.
> >
> > Note 'file' and 'eval'.
> >
> > This means that those variables will not be accessible anywhere
> > outside of that file. Not even after a do, require, use or eval.
> >
> 
> Ok. I didn't even realize that this was a problem. I should have... but
> didn't.

That's ok. it takes a while to get used to all of Perl's different
modes of operation and various scoping rules.

> I am writing a text-to-XML parser that operates on a CSV raw data file. As
> such, I have nearly 530 lines of variable definitions/initializations...
> defining tags, attributes and data structures. I would simply like to move
> them into another file and include them back into my Perl script,
> txt2xml.pl.
> 
> So, really, I don't think that what I'm doing requires that I create a Perl
> Module. But, I was doing that because those were the only examples that
> seemed to come close to the thing I was trying to do.

There are several ways this can be done, and is generally done. 

You could write a configuration file, that you parse. There are
several modules on CPAN that might help you with that. 

You can put all your configuration variables in a single hash. Perl's
standard Config.pm also does this, and it allows you to have a large,
large number of variables, all without polluting your name space,
apart from a single variable. Then you have one other choice: you make
this variable a global in your main program, and you do, eval or
require the config file. Alternatively, you write it as a real module,
and you export the hash name.

There are various other ways, but I'm not going to go into all that. I
happen to believe the hash method is probably what you really want.

You could have a look at the code for the Config.pm module that ships
with Perl. Here's a short example that does the same:

# cat datadefs.pm
package datadefs;
use Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(%Datadefs);

%Datadefs = (
    foo => 'banana',
    bar => 'pineapple',
    baz => 'orange',
);
# cat proggie
#!/usr/local/bin/perl -w
use strict;

use datadefs;
print "$Datadefs{foo}\n";

# ./proggie
banana
#

But I definitely would try to avoid using all those variable names.
Make sure you put datadefs.pm somehwere where perl will find it.

To read some more about the Config module:

# perldoc Config

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 42.6% of statistics is made up on the
Commercial Dynamics Pty. Ltd.   | spot.
NSW, Australia                  | 


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

Date: Tue, 10 Oct 2000 23:11:05 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: included files: missing one important concept...
Message-Id: <ywTE5.217$6I3.176315@news.pacbell.net>


hi kent. so it does. it worked (although i presumed it wouldn't: i
remembered checking this a little over a month ago when i had to write my
last perl script... and i got an error.) it is entirely possible that i did
something wrong when i checked last... but i can't imagine what.

brian

> I just checked, and it works fine for me, using Build 522 from
> ActiveState.  Perldoc.bat is in the Perl/bin (will I get flamed
> for writing "perl/bin", or "PERL/BIN"?) subdirectory.  If you have
> your PATH set to include Perl/bin, you should be fine.
>
> -Kent
>




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

Date: Tue, 10 Oct 2000 23:28:20 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: included files: missing one important concept...
Message-Id: <JMTE5.220$6I3.179994@news.pacbell.net>


Well, as I said to Jeff in the other thread, I will have to look into this
method that both of you are proposing. Right now it too late to even attempt
it, so I will tackle it tomorrow.

Thanks for all of your help Martien.

Brian




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

Date: Tue, 10 Oct 2000 21:58:48 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: included files: really confused, and perldoc doesn't help
Message-Id: <39E3F388.D924692@vpservices.com>

Brian McDonald wrote:
> 
> I am very confused about how to include a file that contains variable defs
> and data structures in a Perl script. I realize that this is a question that
> often draws a RTFM response... but I've read the (ActiveState) docs and
> still don't understand what to do.

Martien has given you a couple of ways to do something that might be
what you are asking about.  I am not sure either what your goal is, but
perhaps this might be a way to accomplish whatever that is:  In the
library file create a function that creates and returns a hash that
holds all your variables.  In the main script, require the library, call
the function, and voila, all your variables are in a hash that can be
used in your main script.  Here's a complete (if braindead) working
example:

# cat my_lib.pl
sub init {
    return (
        foo => 'simpsons',
        bar => ['homer','marge','bart']
    );
}
1;

# cat my_script
#!perl -w
use strict;
require './my_lib.pl';
my %cfg = init();
print $cfg{foo};

# ./my_script
simpsons


-- 
Jeff


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

Date: Tue, 10 Oct 2000 23:25:50 -0700
From: "Brian McDonald" <mcdonabNO@SPAMyahoo.com>
Subject: Re: included files: really confused, and perldoc doesn't help
Message-Id: <nKTE5.219$6I3.179088@news.pacbell.net>


Thanks Jeff. It looks like I have a little bit of work to do to understand
the method you propose. If I have trouble with it, I'll post tomorrow.

Thanks again.

Brian




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

Date: Tue, 10 Oct 2000 22:28:28 -0700
From: "Mark" <mark@mediamasters.net>
Subject: Is perl object oriented?
Message-Id: <qVSE5.65768$Sr.64584@newsfeed.slurp.net>

Is perl a object oriented language?

and

What is an object oriented language?







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

Date: Wed, 11 Oct 2000 04:08:07 GMT
From: juump@my-deja.com
Subject: MacPerl's unlink: Where do files go?
Message-Id: <8s0p33$dja$1@nnrp1.deja.com>

When I use "unlink" with MacPerl5, the unlinked file doesn't go into the
trash as I expected, it simply disappears! Is the file available
anywhere, or is it just instantly erased?


Steve

P.S. - No, I didn't unlink anything important, just wondering....


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 11 Oct 2000 15:09:57 +1000
From: jason <elephant@squirrelgroup.com>
Subject: Re: newbie: pws and active perl
Message-Id: <MPG.144ea12f23bd9c7898980c@localhost>

Pieter Overbeeke wrote ..
>Hi all, 
>
>I'm trying to get cgi (perl) scripts working on pws but i'm bot being
>very succesfull yet. So i hope someone can help me.
>
>I am running pws on win98. I have installed activeperl, set the
>mimetypes right, in the registry, in
>HKEY_LOCAL_MACHINE/System/CurrentControlSet/Services/w3svc/parameters/Script
>Map i have added .pl .cgi and .plx which refer to c:/perl/bin/perl.exe
>%s %s (also tried c:/perl/bin/perl5.6.0.exe %s %s).

c:/perl/bin/perl.exe is not a valid Windows path .. while you can use 
forward slashes in native Perl functions - you cannot use them in 
everything related to Perl

c:\perl\bin\perl.exe is a valid Windows path .. if it's also the path to 
your perl.exe then that might solve your problem

btw .. if you install ActivePerl *after* installing PWS then it should 
add the appropriate script mappings for you

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Wed, 11 Oct 2000 07:48:12 +0200
From: Jimmy Lantz <webmaster@ostas.lu.se>
Subject: OPEN file efficiancy issue,
Message-Id: <39E3FF18.D7ACBAE9@ostas.lu.se>

Hi,
I have some questions about OPEN and efficiancy issues regarding open
and filehandling.
I welcome all suggestions for improvements etc.
Regards.
Jimmy Lantz

FIRST: Is it faster to say:

open(IN, "<$dictfile") or die "cannot read $dictfile: $!";
while (<IN>) { full_matchline($_); }
close(IN);

than

open(IN, "<$dictfile") or die "cannot read $dictfile: $!";
while ($line = <IN>)
 { part_matchline($line); }
close(IN); 


SECONDLY (question about the snippet below):
 
Is it faster not to close(IN) and then do a second "while"
on the file or close the file and reopen it? (This file is at least 3000 rows)
Is it better to read everything into a array and then do an foreach?
(I've heard this takes up a lot of memory).


###################
#open file and do match and add hits to @hits;
open(IN, "<$dictfile") or die "cannot read $dictfile: $!";
while (<IN>) {
full_matchline($_);
}
close(IN); 

$amountofhits = scalar(@hits);

#if no hits and the $hex scalar contains more then 4 chars then  do a
partial match. Then add hits to @hits#
if ($amountofhits == 0 && length($hex) >= 4)
{
open(IN, "<$dictfile") or die "cannot read $dictfile: $!";
while ($line = <IN>)
 {
part_matchline($line);
 }
}
close(IN);


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

Date: Wed, 11 Oct 2000 00:05:06 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: OPEN file efficiancy issue,
Message-Id: <39E41122.C5C07408@stomp.stomp.tokyo>

Jimmy Lantz wrote:

(snipped)

> I have some questions about OPEN and efficiancy issues 
> regarding open and filehandling.

> full_matchline($_);

> part_matchline($line);


> I welcome all suggestions for improvements etc.



An improvement would be to write code which
produces results. Although not fatally flawed,
neither of your example code produce output.
How could you compare relative speed and
efficieny with code which does nothing nor
includes other processes which will affect
both speed and efficiency?

Post code which works, then ask your question.


Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4579
**************************************


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