[22777] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4998 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 17 11:05:51 2003

Date: Sat, 17 May 2003 08:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 17 May 2003     Volume: 10 Number: 4998

Today's topics:
    Re: [The/My] trouble with Perl <geenspam@geenspam.biz>
    Re: [The/My] trouble with Perl <geenspam@geenspam.biz>
        click submit ->starts downloading perl file......dont w (Ashley)
    Re: click submit ->starts downloading perl file......do <REMOVEsdnCAPS@comcast.net>
    Re: click submit ->starts downloading perl file......do <nobody@dev.null>
    Re: click submit ->starts downloading perl file......do <noreply@gunnar.cc>
    Re: how do i hide a password? <Juha.Laiho@iki.fi>
        Losing value in require statement <dingdongy2k@hotmail.com>
    Re: Losing value in require statement <jurgenex@hotmail.com>
    Re: Losing value in require statement <noreply@gunnar.cc>
        Perl code segment <bigbadbob@yahoo.com>
    Re: possible bug in m// ? (Sara)
    Re: possible bug in m// ? <abigail@abigail.nl>
        ReadLine with timeout <skoehler-remove-for-no-spam@upb.de>
        search through @INC for file to open <jaspax@u.washington.edu>
    Re: search through @INC for file to open <tassilo.parseval@rwth-aachen.de>
    Re: search through @INC for file to open <jaspax@u.washington.edu>
    Re: search through @INC for file to open (Jay Tilton)
        The chomp did it <dingdongy2k@hotmail.com>
    Re: Visual Basic Conversion to Perl.... Thunder9_NOSPAM@dsemail.net
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 17 May 2003 09:34:53 +0200
From: Henk van Bree <geenspam@geenspam.biz>
Subject: Re: [The/My] trouble with Perl
Message-Id: <3ec5d808$0$49105$e4fe514c@news.xs4all.nl>

Janek Schleicher wrote:

>> If "perl -e MCPAN 'install GD'" gets you nowhere but
>> pages and pages of errors it is not trivial to know
>> how to fix things. Not for me, at least.
> 
> That's why there are such Perl user lists like this one in the world.
> If you have a specific problem, just ask in the usenet (or on
> www.perlmonks.org). Given a good and detailed description, you'll get
> normally good and detailed answers specific to your problem.

True. My original problem is now solved, for which I have this
forum to thank.

> But it's to easy to say, that it is a design error of Perl not to bundle
> in e.g. Tk or any other widget set automatically. IMHO, it's one of the
> best design features of Perl. It's similar to Linux. It also has no built
> in window manager. (Of course, Xwindow system is the de-facto-standard,
> but it's not the only way, and it's right not to bundle in the Linux).

I think you are correct on an abstract level, but in the harsh outside world
it sometimes pays off to have consistancy and de-facto tools to work with.

Is is beneficial for an end-user to have three applications with three
different widget sets? I think it isn't, and for me this weighs in heavy
on the balance of it all. 

Anyway, kudos to all that responded to my cry for help!

Henk



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

Date: Sat, 17 May 2003 09:39:10 +0200
From: Henk van Bree <geenspam@geenspam.biz>
Subject: Re: [The/My] trouble with Perl
Message-Id: <3ec5d909$0$49105$e4fe514c@news.xs4all.nl>

Simon Andrews wrote:

>> One big .exe (for the Windows boxes) is prefered.
> 
> You will probably have to compile your own version of Perl for this to
> work then as the ActiveState version uses shared libraries.  It's not
> that much hassle distributing perl56.dll (or whatever) with your app
> though.  It also means that if you're distributing several applications
> you only have to send the dll once.

A handful of dll's is no problem. I've got it (a test setup) working
now and I'm very happy with it.

In hindsight most of my problem was caused by inexperience with the
whole compiler setup, instead of just adding "#!/usr/bin/perl" on top.

I've learned some valuable lessons from this episode!

Henk





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

Date: 17 May 2003 04:39:00 -0700
From: hot_geezer@hotmail.com (Ashley)
Subject: click submit ->starts downloading perl file......dont want it to happen
Message-Id: <f560e709.0305170339.60bb2308@posting.google.com>

i got a simple form which looks like this:

<form name="feedback" action="cgi-bin/feedback.pl" method="post">

  <input type="text" name="name" value="">

  <select name="age" size="1">
  <option selected>Choose Age...</option>
  <option value="under16">Under 16</option>
  <option value="17-20">17 - 20</option>
  <option value="21-30">21 - 30</option>
  <option value="31-40">31 - 40</option>
  <option value="over41">Over 41</option>
  </select>

  <textarea name="comment" rows="3" cols="25"></textarea>
  <input type="submit" name="submit" value="Send Feedback!">
  <input type="reset" name="clear" value="Clear Feedback!">

</form>

The perl script is as follows (its a tutorial book, which im using and
should work with any form):

#!/C:/perl/bin/perl.exe

my(%form);

getFormData(/%form);

# data procesing statements

sub getFormData {
	my($hashRef) = shift;
	my($buffer) = "";

	if ($ENV{'REQUEST_METHOD'} eq 'GET') {
		$buffer = $ENV{'QUERY_STRING'};
	}
	else {
		read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	}

	foreach (split(/&/, $buffer)) {
		my($key, $value) = split(/=/, $_);
		$key = decodeURL($key);
		$value = decode($value);
	}
}

sub decodeURL {
	$_ = shift;
	tr/+/ /;
	s/%(..)/pack('c', hex($1))/eg;
	return($_);
}

/////////////////////
When the submit button is pressed, Internet Explorer brings up a
download box asking if i want to save it or open it.

What i want it to do is execute the perl script, how can i do this?

*********************
OS:            Windows 2000
Server:        Apache (latest version and auto configured for use with
perl)
Perl version:  Indigo Perl
Experiance:    Begineer
*********************


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

Date: Sat, 17 May 2003 07:35:27 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: click submit ->starts downloading perl file......dont want it to happen
Message-Id: <Xns937E575242301sdn.comcast@216.166.71.239>

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

hot_geezer@hotmail.com (Ashley) wrote in
news:f560e709.0305170339.60bb2308@posting.google.com:

> The perl script is as follows (its a tutorial book, which im using
and
> should work with any form):

No, it doesn't.  Use the CGI.pm module that comes with Perl.  NEVER
write your own function, or copy someone else's function, for parsing
CGI data unless you're doing it as a learning exercise.  The
getFormData function that you showed has at least two bugs in it.


> /////////////////////
> When the submit button is pressed, Internet Explorer brings up a
> download box asking if i want to save it or open it.
> 
> What i want it to do is execute the perl script, how can i do
this?
> 
> *********************
> OS:            Windows 2000
> Server:        Apache (latest version and auto configured for use
with
> perl)
> Perl version:  Indigo Perl
> Experiance:    Begineer
> *********************

This is a server configuration issue, not a perl issue.  You need to
tell Apache to execute the script rather than to serve it as a file
for download.  You have to make sure the CGI script is executable by
the user who is running the web server, and you need to make sure
that the Apache ExecCGI flag is turned on in the directory where the
script resides.

HTH
- -- 
Eric
print scalar reverse sort qw p ekca lre reh 
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13

iD8DBQE+xixfY96i4h5M0egRAq9tAKDOYxya947kycQv5wpYTa16mtwSZQCfZgL3
bfhFkPs8acTcIhQPkRBRvm0=
=Wu3e
-----END PGP SIGNATURE-----


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

Date: Sat, 17 May 2003 13:20:54 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: click submit ->starts downloading perl file......dont want it to happen
Message-Id: <3EC636B9.6000907@dev.null>



Ashley wrote:

> i got a simple form which looks like this:
> 
> <form name="feedback" action="cgi-bin/feedback.pl" method="post">


[some more HTML]


> The perl script is as follows (its a tutorial book, which im using and
> should work with any form):
> 
> #!/C:/perl/bin/perl.exe
> 
> my(%form);
> 
> getFormData(/%form);


I'm almost certain that your book actually has
	getFormData(\%form);
Once you get your script to work, perl will complain about that typo.


> 
> # data procesing statements
[more Perl code]
> 
> /////////////////////
> When the submit button is pressed, Internet Explorer brings up a
> download box asking if i want to save it or open it.


That most likely is an issue with the server configuration. 
www.apache.org has extensive documentation that may help you.





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

Date: Sat, 17 May 2003 15:03:30 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: click submit ->starts downloading perl file......dont want it to happen
Message-Id: <ba5bvo$p67ia$1@ID-184292.news.dfncis.de>

Ashley wrote:
> i got a simple form

<snip>

> The perl script is as follows (its a tutorial book, which im using and
> should work with any form):

That script is incomplete. Besides a couple of typos, it doesn't do 
anything with the form data.

> #!/C:/perl/bin/perl.exe
----^
Remove that slash.

The rest of the script should better look something like this:

     use strict;
     use warnings;
     use CGI::Carp 'fatalsToBrowser';
     use CGI ':standard';

     print header;
     for (param) { print "$_ = ", param($_), "<br>\n" }

> What i want it to do is execute the perl script, how can i do this?

The above script may be executed. But you should decide what you want 
the script to do, and program accordingly.

/ Gunnar

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



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

Date: Sat, 17 May 2003 07:37:01 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: how do i hide a password?
Message-Id: <ba4oqp$p53$1@ichaos.ichaos-int>

google@billjonline.com (bill j) said:
>my site is hosted remotely and, frankly, I don't want the people who
>host it to have access to my DB password which is visible if they were
>to look at my Perl script.
 ...
>Is there a way to encrypt/decrypt it so that it is only visible to the
>script as it is running?

This question comes up in various forms every now and then, and the
short answer is "no".

If your program needs to present some data to another program, the
data needs to be available to your program - and thus everything
needed for the data to be available will be with your program (which,
as you say, is hosted remotely). So, essentially the database password
is available to those hosting your site.

Some further questions (which do not change the answer):
Is your database hosted with the same company?
- if so, the hosting company already has access to your database,
  regardless of hacing your db password
- and even if not, they'd be able to listen to the traffic between
  your program and the database (unless you use some secure channel
  such as SSL to communicate with your database)
  - and even with the secure channel, your provider is the one
    giving you the programs to establish the secure channel, so
    you have then to trust your provider to provide trustworthy
    versions of those programs

So, if you do not trust the admin personnel at your provider, you need
to find another provider. If you categorically do not trust any outside
admin personnel, you cannot use managed hosting services (you're limited
to buying/renting your own machine and either providing a location your-
self, or renting some space in a server hotel -- with the latter, though,
come the issues whether or not you trust the hotel physical security).
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
         PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: Sat, 17 May 2003 12:33:12 GMT
From: "Travis" <dingdongy2k@hotmail.com>
Subject: Losing value in require statement
Message-Id: <c_pxa.1354$rO.177980@newsread1.prod.itd.earthlink.net>

I use this to get the time in a perl script

$t = time();
($sec,$min,$hour,$dom,$mon,$year,$wday,$yday,$isdst) = localtime($t);
$now = localtime($t);

I use a require statement after that to execute some other lines of code.
(ex:  require 'otherlines.pl';)

That has worked fine except that I seem to lose the value in  $now
(ex:  Sat May 17 00:08:10 2003  )

The rest of the code in the require statement is executed properly.

So even after the require statement is executed , and printed blanks for
$now, the main script can still print the value correctly.

Any ideas?

Travis




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

Date: Sat, 17 May 2003 13:07:42 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Losing value in require statement
Message-Id: <yuqxa.9737$Hy3.4321@nwrddc02.gnilink.net>

Travis wrote:
> I use this to get the time in a perl script
>
> $t = time();
> ($sec,$min,$hour,$dom,$mon,$year,$wday,$yday,$isdst) = localtime($t);
> $now = localtime($t);
>
> I use a require statement after that to execute some other lines of
> code. (ex:  require 'otherlines.pl';)
>
> That has worked fine except that I seem to lose the value in  $now
> (ex:  Sat May 17 00:08:10 2003  )
>
> The rest of the code in the require statement is executed properly.
>
> So even after the require statement is executed , and printed blanks
> for $now, the main script can still print the value correctly.

Let me try to understand:
Your problem is that the value of the variable main::$now cannot be accessed
in the module otherlines.pl, right?

That is not the way simple modules work. And I don't think that Perl
supports parameterized modules.

Can't you just use a "do" instead of the "require"?

jue




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

Date: Sat, 17 May 2003 15:12:30 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Losing value in require statement
Message-Id: <ba5cgl$pmseu$1@ID-184292.news.dfncis.de>

Travis wrote:
> I use this to get the time in a perl script
> 
> $t = time();
> ($sec,$min,$hour,$dom,$mon,$year,$wday,$yday,$isdst) = localtime($t);
> $now = localtime($t);

Are you doing anything with the variables on the second line? If not, 
this should be enough for setting $now:

     $now = localtime;

> I use a require statement after that to execute some other lines of code.
> (ex:  require 'otherlines.pl';)
> 
> That has worked fine except that I seem to lose the value in  $now
> (ex:  Sat May 17 00:08:10 2003  )

Sounds strange. Please show us a complete program that illustrates the 
problem.

/ Gunnar

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



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

Date: Sat, 17 May 2003 12:31:30 +1000
From: "Bob" <bigbadbob@yahoo.com>
Subject: Perl code segment
Message-Id: <ba5h26$pbgv2$1@ID-82947.news.dfncis.de>

Can anyone assist in helpiing decode this code fragment ?
Or tell me what it might be doing ?

($level, $group, $status, $failed) = ($line =~
/^NetWorker\s+Savegroup:\s+\((\w+)\)\s(.*)\s(\w+),\s+\d+\sclient\(s\)\s\((.*
)\)\n$/);






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

Date: 16 May 2003 21:36:47 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: possible bug in m// ?
Message-Id: <776e0325.0305162036.703542e2@posting.google.com>

Abigail <abigail@abigail.nl> wrote in message news:<slrnbcb8lp.mth.abigail@alexandra.abigail.nl>...
> dan baker (botfood@yahoo.com) wrote on MMMDXLV September MCMXCIII in
> <URL:news:13685ef8.0305161231.2c4bae1d@posting.google.com>:
> ;;  I am attempting to catch illegal formats for zip codes, and think I
> ;;  have a bug in the "exact number of times" part of regex. the snippet
> ;;  is:
> ;;  
> ;;  	unless ( ($MemberZip =~ m/\d{5}/) or ($MemberZip =~ m/\d{5}\-\d{4}/))
> ;;  {
> ;;  	$FormErrorMsg .= " \n<li> Zip must be either 5 digit, or 5+4 format."
> ;;  }
> ;;  
> ;;  What is happening is that values with more than 5 digits are passing
> ;;  right thru without getting caught. Am I doing something wrong with
> ;;  regex or is this a bug? Running perl 5.00503 from activestate on
> ;;  windows98.
> 
> 
> Your perception is wrong.  /\d{5}/ will match any string that contains
> 5 digits in a row. A string consisting of 6 digits will contain 5 in 
> a row, and hence it matches. If you want to match exactly 5 digits,
> use anchors: /^\d{5}$/.
> 
> For zip codes, you could also use Regexp::Common:
> 
>     use Regexp::Common qw /zip/;
> 
>     unless ($MemberZip =~ /^$RE{zip}{US}$/) {
>         ....
>     }
> 
> 
> Abigail

not exactly- a12345 matches what he wants but fails your test.

 /\D?\d{5}\D?/ might be more universal?

-Gx


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

Date: 17 May 2003 10:42:50 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: possible bug in m// ?
Message-Id: <slrnbcc4ha.mth.abigail@alexandra.abigail.nl>

Sara (genericax@hotmail.com) wrote on MMMDXLVI September MCMXCIII in
<URL:news:776e0325.0305162036.703542e2@posting.google.com>:
;;  Abigail <abigail@abigail.nl> wrote in message news:<slrnbcb8lp.mth.abigail@alexandra.abigail.nl>...
;; > dan baker (botfood@yahoo.com) wrote on MMMDXLV September MCMXCIII in
;; > <URL:news:13685ef8.0305161231.2c4bae1d@posting.google.com>:
;; > ;;  I am attempting to catch illegal formats for zip codes, and think I
;; > ;;  have a bug in the "exact number of times" part of regex. the snippet
;; > ;;  is:
;; > ;;  
;; > ;;  	unless ( ($MemberZip =~ m/\d{5}/) or ($MemberZip =~ m/\d{5}\-\d{
;; > ;;  {
;; > ;;  	$FormErrorMsg .= " \n<li> Zip must be either 5 digit, or 5+4 for
;; > ;;  }
;; > ;;  
;; > ;;  What is happening is that values with more than 5 digits are passing
;; > ;;  right thru without getting caught. Am I doing something wrong with
;; > ;;  regex or is this a bug? Running perl 5.00503 from activestate on
;; > ;;  windows98.
;; > 
;; > 
;; > Your perception is wrong.  /\d{5}/ will match any string that contains
;; > 5 digits in a row. A string consisting of 6 digits will contain 5 in 
;; > a row, and hence it matches. If you want to match exactly 5 digits,
;; > use anchors: /^\d{5}$/.
;; > 
;; > For zip codes, you could also use Regexp::Common:
;; > 
;; >     use Regexp::Common qw /zip/;
;; > 
;; >     unless ($MemberZip =~ /^$RE{zip}{US}$/) {
;; >         ....
;; >     }
;; > 
;; > 
;; > Abigail
;;  
;;  not exactly- a12345 matches what he wants but fails your test.


I didn't get the impression 'a12345' is ok (why would that be ok, when
replacing the 'a' with '6' suddenly makes it wrong?).

;;   /\D?\d{5}\D?/ might be more universal?


    $ perl -wle 'print "Nope" if "123456" =~ /\D?\d{5}\D?/'
    Nope

You'd need to use something like /(?:^|\D)\d{1,5}(?:\D|$)/.


Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: Sat, 17 May 2003 15:23:06 +0200
From: =?ISO-8859-1?Q?Sven_K=F6hler?= <skoehler-remove-for-no-spam@upb.de>
Subject: ReadLine with timeout
Message-Id: <ba5dac$l7$03$1@news.t-online.com>

hi,

i badly need a ReadLine-funtion that returns within a given timeout. 
Does anybody know such a module? or any way to do this?



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

Date: Fri, 16 May 2003 23:08:45 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: search through @INC for file to open
Message-Id: <Pine.A41.4.55.0305162305530.78422@dante18.u.washington.edu>

Is there an easy way to look through all of the directories in @INC trying
to open() a file there? I've looked through the man pages, and nothing
leaps out at me. For now I'm just using a small loop, like:

    my $filename = "somefile";
    for (@INC) {
	last if open FILE "$_/$filename";
    }

But it seems like there should be an easier way to do this.

Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"


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

Date: 17 May 2003 06:49:42 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: search through @INC for file to open
Message-Id: <ba4m26$62t$1@nets3.rz.RWTH-Aachen.DE>

Also sprach JS Bangs:

> Is there an easy way to look through all of the directories in @INC trying
> to open() a file there? I've looked through the man pages, and nothing
> leaps out at me. For now I'm just using a small loop, like:
> 
>     my $filename = "somefile";
>     for (@INC) {
> 	last if open FILE "$_/$filename";
>     }
> 
> But it seems like there should be an easier way to do this.

It really depends on what you mean by "open". If the files in question
are supposed to be perl scripts or modules, Perl has built-in means to
open them, namely do(), use() and require(). So if you want to make use
of these 'shortcuts', you have to make sure that your files are in a
suitable format. Pure data can often be turned into a Perl module and
conveniently included with one of the above functions. So what do you
have in mind?

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


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

Date: Sat, 17 May 2003 00:16:04 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: search through @INC for file to open
Message-Id: <Pine.A41.4.55.0305170012000.78422@dante18.u.washington.edu>

Tassilo v. Parseval sikyal:

> Also sprach JS Bangs:
>
> > Is there an easy way to look through all of the directories in @INC trying
> > to open() a file there? I've looked through the man pages, and nothing
> > leaps out at me. For now I'm just using a small loop, like:
> >
> >     my $filename = "somefile";
> >     for (@INC) {
> > 	last if open FILE "$_/$filename";
> >     }
> >
> > But it seems like there should be an easier way to do this.
>
> It really depends on what you mean by "open". If the files in question
> are supposed to be perl scripts or modules, Perl has built-in means to
> open them, namely do(), use() and require(). So if you want to make use
> of these 'shortcuts', you have to make sure that your files are in a
> suitable format. Pure data can often be turned into a Perl module and
> conveniently included with one of the above functions. So what do you
> have in mind?

The files are pure data in the form of a text file that the module parses
line-by-line. My goal is to provide a default configuration file in the
modules installation directory that the user can load just as easily as
they would load a file of their own. I.e. I don't want the user to have to
use lib '/usr/share/perl/' or open something with a full path, or anything
like that.

It would be a bit of work to turn the flat file into parseable code, but
that may be the best solution.

Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog

Jesus asked them, "Who do you say that I am?"

And they answered, "You are the eschatological manifestation of the ground
of our being, the kerygma in which we find the ultimate meaning of our
interpersonal relationship."

And Jesus said, "What?"


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

Date: Sat, 17 May 2003 08:04:51 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: search through @INC for file to open
Message-Id: <3ec5eaa6.341900477@news.erols.com>

JS Bangs <jaspax@u.washington.edu> wrote:

: Tassilo v. Parseval sikyal:
: 
: > Also sprach JS Bangs:
: >
: > > Is there an easy way to look through all of the directories in @INC trying
: > > to open() a file there? I've looked through the man pages, and nothing
: > > leaps out at me. For now I'm just using a small loop, like:
: > >
: > >     my $filename = "somefile";
: > >     for (@INC) {
: > > 	last if open FILE "$_/$filename";
: > >     }
: > >
: > > But it seems like there should be an easier way to do this.
: >
: > It really depends on what you mean by "open".
: 
: The files are pure data in the form of a text file that the module parses
: line-by-line. My goal is to provide a default configuration file in the
: modules installation directory that the user can load just as easily as
: they would load a file of their own. I.e. I don't want the user to have to
: use lib '/usr/share/perl/' or open something with a full path, or anything
: like that.

Sounds like something I got into discussing recently.

Check groups.google.com for the thread starting at 
Message-ID: <ntm76vskmtc4e89rph5vlk7uigklssmfqo@4ax.com>

The information there should at least provide a starting point for
you, if not an outright solution.

: Jesse S. Bangs jaspax@u.washington.edu
[snip]

An eleven-line sig is a bit more than adequate.
Please at least use the standard "-- " sig delimiter to separate it
from your articles' content.



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

Date: Sat, 17 May 2003 12:24:34 GMT
From: "Travis" <dingdongy2k@hotmail.com>
Subject: The chomp did it
Message-Id: <6Spxa.1343$rO.177216@newsread1.prod.itd.earthlink.net>

You were right.
It was the chomp that was needed.

Thanks

"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3EC1A747.6@rochester.rr.com...
> Travis wrote:
>
> > print MEMCHK "$used_timein[$j]\n";
> >
> > I am writing to file and simply want to get each line with a single line
> > feed.
> >
> > For some reason I get the single line feed when I leave off the \n and I
get
> > a double line feed when
> > I leave it in?
> >
> > Any ideas?
>
>
> Sure.  Leave off the \n :-).
>
>
> You undoubtedly have a newline at the end of array element
> $used_timein[$j].  Perhaps you read it from a file and neglected to
> chomp it?
>
> -- 
> Bob Walton
>
>




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

Date: Sat, 17 May 2003 14:33:25 GMT
From: Thunder9_NOSPAM@dsemail.net
Subject: Re: Visual Basic Conversion to Perl....
Message-Id: <3hiccv41ajfcrue8oq08aenkjcvmb4h28i@4ax.com>

I got a fantastic response via email, thought I'd share with everyone
(minus their name/address):

On Friday 16 May 2003 07:04 pm, Thunder9_NOSPAM@dsemail.net posted to 
comp.lang.perl.misc:

> I need to convert a VB program I just wrote into perl.  If you have a
> minute could you please look at the section of code below and give me
> a pointer on just *one* (or more if you want) item?
> 
> The following are the constructs I need to imitate in perl in order to
> do my conversion....  the Visual Basic has been dumbed-down a little
> so don't rely on any of this for actual working code.
>  
> 1. Structured Types
>  
>  Dim MyObject as new MyType
>  MyObject.value1 = "Fred"
>  MyObject.value2 = "Barney"

Depending on what you are trying to accomplish, you could use a
pacakge (see 
the perltoot manual page for a thorough discussion), but that would
only be 
necessary if you needed to check the type later, or if the type
represents 
a class with methods. Since there's no evidence of that, the simplest 
answer is:

%MyObject = ( 'value1' => 'Fred', 'value2' => 'Barney' );


  
> 2. Collections Object
>  
> A collections object that you can add structured types to, with a hash
> value.  (All hash values are guaranteed unique so I don't need to
> managage collisions).  Example
>  
>  Dim Col as new collection
>  Dim hashvalue as string
>  Dim MySecondObject as MyType
>  
>  hashvalue = MyObject.value1
>  if Col.exists(hashvalue) then
>  MySecondObject = Col.Lookup(hashvalue)
>  else
>  Col.AddItem(MyObject, hashvalue)
>  endif

%Col;
$hashvalue = $MyObject{'value1'};
if (defined $Col{$hashvalue})
{ $MySecondObject = $Col{$hashvalue}; }
else
{ $Col{$hashvalue} = \%MyObject; }


>  
>  3. File Handling FindFirst and FindNext
>  
>  Search a single level directory using FindFirst and FindNext as
>  follows:
>  
>  hFile = FindFirstFile("C:\*.*", wfd)
>  
>  While hFile <> INVALID_HANDLE
>  If IsDirectory(wfd) Then
>  ' Directory Processing
>  Else
>  ' File Processing
>  End If
>  FindNextFile(hFile, wfd)
>  
>  Wend

foreach $wfd (<C:\\*.*>)
{ processdirectory($wfd) if -d $wfd; }


>  
>  4.  Other File Handling:
>     4.1 Get last modified date of a file

        $lastmodified = (stat $filename)[9];


>     4.2 Test if file exists based on full path

        -f $fullpath;


>  
>  5. String Functions:
>  
>    5.1 Test for Match against Regular Expression

        /regular expression here/;


>    5.2 Emulate Instr, Left$, Right$, and Mid$ functions.

        substr() does all three cases

>    5.3 Concatenate Strings

        $a . $b
or      join("", $a, $b);


>    5.4 Assignment to a variable based on a reg expression match within
> another string

        $string =~ /regular expression/$var = $&/e;


>    5.5 Convert to upper case.

        $string =~ tr/a-z/A-Z/;


>  
> 7. Modular Design
>  
>    7.1 Functions with parameters

sub func
{
  print "parameters = ", join(", ", @_), "\n";
}


>    7.2 Recursion

sub factorial
{
  $n = shift;
  $n *= factorial($n-1) if $n > 1;
  return $n;
}


>    7.3 Return Values

sub return_two_values
{
   return ("first", "second");
}


>    7.4 Local Variables

my $localvariable;


>  
> 
> Thanks...
> 
> 
> NOSPAM is antispam

NOSPAM is antispam


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

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


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