[10606] in Perl-Users-Digest
Perl-Users Digest, Issue: 4198 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 11 14:07:24 1998
Date: Wed, 11 Nov 98 11:00:25 -0800
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, 11 Nov 1998 Volume: 8 Number: 4198
Today's topics:
Re: & for subroutines Was:Re: Perl "Newbie" Needs Hel <merlyn@stonehenge.com>
Re: & for subroutines Was:Re: Perl "Newbie" Needs Hel <r28629@email.sps.mot.com>
Re: & for subroutines Was:Re: Perl "Newbie" Needs Hel <dgris@rand.dimensional.com>
Re: <<My Sort Problem>> dave@mag-sol.com
Re: <<My Sort Problem>> <nospam@see.signature>
Anyone have comm.pl examples? <jim.mosier@usa.net>
Re: attaching a jpeg <merlyn@stonehenge.com>
calling by reference <avitala@macs.biu.ac.il>
Re: Command Line Parameters? <r28629@email.sps.mot.com>
Comparing Arrays -- infinite loop? (Oliver Moffat)
Re: Comparing Arrays -- infinite loop? <baliga@synopsys.com>
Re: concurrently writing to a file without doing flock <r28629@email.sps.mot.com>
Re: concurrently writing to a file without doing flock (Andrew M. Langmead)
Dial-in or local LAN? <kennedy_r@hlhont.moh.gov.on.ca>
Re: e-mail (M.)
Re: Emulate dirname and basename in perl?? <r28629@email.sps.mot.com>
Re: Hash help <uri@sysarch.com>
help explain a regx example?! <dtbaker-@busprod.com>
Re: Help please - Testing if a substring in a certain p (Andre L.)
Help with Perl5 <Carlos.Woodcock@mail.ineti.pt>
Re: Help with Perl5 (Erik)
Re: help:counting the number of occurences of a specifi (Tore Aursand)
Re: help:counting the number of occurences of a specifi (Joergen W. Lang)
Re: How do I sort this list by "port" number? (Sean McAfee)
Re: Installing a Perl module to Active Perl <ludlow@us.ibm.com>
Re: Installing a Perl module to Active Perl <perlguy@technologist.com>
Is this possible using the truncate command Rafely@xxiname.com
Re: Is this possible using the truncate command (Erik)
Passing Perl Hash Through DCOM <randy.omeara@lmco.com>
Re: percentages <dixonmat@pouch.com>
Re: Perl class question <jdporter@min.net>
Re: PERL is TOO flexible <jeromeo@atrieva.com>
Re: PERL is TOO flexible <r28629@email.sps.mot.com>
Re: Perl5 Win32::ODBC SQL Statement Involing dates (Steve Linberg)
Re: pwd without backticks? <uri@sysarch.com>
Roaming Profiles on Win32 (James Normington)
Re: String Split Help bigcheese@my-dejanews.com
Re: String Split Help (Andre L.)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Nov 1998 17:25:34 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: & for subroutines Was:Re: Perl "Newbie" Needs Help Debugging Code
Message-Id: <8clnlixhto.fsf@gadget.cscaper.com>
>>>>> "bj" == bj <bradw@newbridge.com> writes:
bj> It goes on to note the cases when the & is required. While the & is
bj> optional in most cases, I do not get the sense that it is deprecated.
I still recommend it strongly in the classes we teach. I do not
expect a new Perl hacker to have to learn the names of *every*
built-in function so as not to collide with them during the time they
are struggling with the basics of call/return. For example, what's
wrong with this code:
open LOG, ">>the-log-file" or die "$!";
sub log { print LOG @_; }
...
log("Starting\n");
do_something();
log("Finishing\n");
Right. You didn't call &log... you called the logarithm function!
Bleh.
So, until they've learned how to determine the names of every
function, it's MUCH easier to prefix all user-defined functions with
&. Learn one step at a time.
print "Just another Perl trainer,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 11 Nov 1998 12:20:06 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: & for subroutines Was:Re: Perl "Newbie" Needs Help Debugging Code
Message-Id: <3649D556.3C339E2F@email.sps.mot.com>
Randal Schwartz wrote:
>
> >>>>> "bj" == bj <bradw@newbridge.com> writes:
>
> bj> It goes on to note the cases when the & is required. While the & is
> bj> optional in most cases, I do not get the sense that it is deprecated.
>
> I still recommend it strongly in the classes we teach. I do not
> expect a new Perl hacker to have to learn the names of *every*
> built-in function so as not to collide with them during the time they
> are struggling with the basics of call/return. For example, what's
> wrong with this code:
>
> open LOG, ">>the-log-file" or die "$!";
> sub log { print LOG @_; }
>
> ...
> log("Starting\n");
> do_something();
> log("Finishing\n");
>
> Right. You didn't call &log... you called the logarithm function!
> Bleh.
>
> So, until they've learned how to determine the names of every
> function, it's MUCH easier to prefix all user-defined functions with
> &. Learn one step at a time.
Perhaps we should encourage the use of capitalized function names (eg.
Log) as user defined functions as to avoid conficting with Perl built-in
functions and possible future reserved words.
-tk
------------------------------
Date: 11 Nov 1998 12:27:20 -700
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: & for subroutines Was:Re: Perl "Newbie" Needs Help Debugging Code
Message-Id: <m3emra58tj.fsf@rand.dimensional.com>
Tk Soh <r28629@email.sps.mot.com> writes:
> Perhaps we should encourage the use of capitalized function names (eg.
> Log) as user defined functions as to avoid conficting with Perl built-in
> functions and possible future reserved words.
Blechh! No.
dgris
--
Daniel Grisinger dgris@rand.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Wed, 11 Nov 1998 16:45:53 GMT
From: dave@mag-sol.com
Subject: Re: <<My Sort Problem>>
Message-Id: <72cf01$tee$1@nnrp1.dejanews.com>
In article <72cbrd$qcn$1@nnrp1.dejanews.com>,
dccobb@yahoo.com wrote:
> In article <72c776$m3p$1@nnrp1.dejanews.com>,
> dave@mag-sol.com wrote:
> >
> > You may think that it would be easier for me to just tell you the answer to
> > your questions, the reason I don't goes back to the old adage about fishing
> > and eating.
> >
> > hth,
> >
> > Dave...
>
> I appreciate you telling me that Perl does have a command for sorting. I
> would also not expect myself to tell someone the answer as research and
> learning by yourself is the only way to find out how things work.
>
> Cheers, Dave
You're very welcome. It's a pleasure to help someone who actually tries to
understand how the newsgroups work and realises why we don't like to hand out
answers on a plate.
Dave...
--
dave@mag-sol.com
London Perl M[ou]ngers: <http://london.pm.org/>
[Note Changed URL]
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Wed, 11 Nov 1998 10:21:29 -0800
From: "J|rgen Exner" <nospam@see.signature>
Subject: Re: <<My Sort Problem>>
Message-Id: <72ckh0$v9r@news.dns.microsoft.com>
dccobb@yahoo.com wrote in message <72bvn1$g6o$1@nnrp1.dejanews.com>...
>Hello all,
>
>I have the following problem:
>
>I have a list as shown below, I need to sort the list on the first column
in
>alphabetical order. The list is currently in a file and would have to
stuffed
>into an array. Is there any sort techniques I could use in Perl, e.g.
Sort,
>incorporating a bubble sort technique?
>
>SJR-01 MR. F
>TCC-03 MR. G
>FFF-04 MR. J
>GHT-09 MR. X
>DCC-34 MR. Z
>SJR-01 MR. T
"sort" is a build-in function of Perl.
See the Camel book, page 217, function "sort", or your favorite man page for
details.
jue
--
J|rgen Exner; microsoft.com, UID: jurgenex
Sorry for this anti-spam inconvenience
------------------------------
Date: Wed, 11 Nov 1998 18:31:52 GMT
From: "MoJi" <jim.mosier@usa.net>
Subject: Anyone have comm.pl examples?
Message-Id: <01be0da2$0232cfa0$750a22a6@jMosier>
New users wanting to use the expect portion of it.
------------------------------
Date: Wed, 11 Nov 1998 17:19:09 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: attaching a jpeg
Message-Id: <8cpvauxi4d.fsf@gadget.cscaper.com>
>>>>> "Gareth" == Gareth Ennis <gary.ennis@strath.ac.uk> writes:
[also stealth-cc'ed... DON'T DO THAT.]
Gareth> Surely if i validate $recip_email so that it cannot contain a " " or a
Gareth> "/" then nobody can cause any damage...???
Uh, legal addresses can contain those. Are you telling me you want
to tell your customers what they can have in their addresses?
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 11 Nov 1998 19:22:02 +0200
From: "Avshi Avital" <avitala@macs.biu.ac.il>
Subject: calling by reference
Message-Id: <72ch8j$mnm$1@cnn.cc.biu.ac.il>
hi guys (and gals),
the following sub excepts a string and returns the last word:
sub get_word {
$_[0] =~ s/\b([^\s]*?)\s*$//;
return $1;
}
obviously it doesn't change the value of the input string (though it
DOES change $_[0] - locally).
what if I wanted it to change it's value (that is: return the last word,
and shorten the input string by one word)?
i suppose it's some use of reference (\)?
thanx for any help!
--
Avshalom Avital
Information Retrieval Laboratory
Bar-Ilan University, Israel
avitala@macs.biu.ac.il
------------------------------
Date: Wed, 11 Nov 1998 12:00:32 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Command Line Parameters?
Message-Id: <3649D0C0.BB321BC2@email.sps.mot.com>
Adrian Aichner wrote:
>
> >>>>> "Koos" == Koos Pol <koos_pol@nl.compuware.com.NO_JUNK_MAIL> writes:
>
> Koos> On Sun, 08 Nov 1998 12:04:38 -0500, Ken Timlin <ktimlin@erols.com> wrote:
> Koos> | do I pass parameters from the command line to my Perl
> Koos> | script? I want to pass it two strings in the following
> Koos> | manner:
> Koos> |
> Koos> | /usr/bin/myprogram string1 string2
> Koos> |
>
> Koos> man perlrun
>
> Or even
>
> perldoc Getopt::Long
>
> for a general way to pass arguments and options according to POSIX
> convention with GNU extensions.
>
> Adrian
Don't you think it might be a bit overkill? Such simple function can be
achieve quite easily by reading @ARGV, at least on my Sun Solaris and
HP-UX (the '/' told me that he was using MS system).
-tk
------------------------------
Date: Wed, 11 Nov 1998 11:52:32 -0500
From: xcom2@popserver.panix.com (Oliver Moffat)
Subject: Comparing Arrays -- infinite loop?
Message-Id: <xcom2-1111981152330001@xcom2.dialup.access.net>
I'm trying to write a Perl script to automate the updating of a flat text
file database. I'm trying to compare the new database of titles to the old
databse of titles and get a list of "Brand New Titles."
Everything goes fine up untill the following chunk of code where the
actual comparison is supposed to happen. When the script gets to this
point it gets stuck and just spins its wheels. Is there an infinite loop
here? Is there a more efficient way to do this?
while (@new_titles)
{
$i = shift (@new_titles); # grab the title on the top
$j = 0;
foreach $k (@old_titles) # compare the new title to each
of the old titles
{
if ($i eq $k) # untill we find a match
{
splice (@old_titles, $j, 1); # remove the matched title from
the old titles list
last; # so we don't check
it again and stop looking
}
elsif ($#old_titles < 1) # but if we're at the end of
the list of old titles
{ # then we found a
brand new title
push (@brand_new_titles, $i); # so we push it onto brand_new_titles
}
else # if we don't find a
match
{
$j++; # increment the
counter and keap looking
}
}
}
------------------------------
Date: Wed, 11 Nov 1998 10:45:20 -0800
From: Yogish Baliga <baliga@synopsys.com>
To: Oliver Moffat <xcom2@popserver.panix.com>
Subject: Re: Comparing Arrays -- infinite loop?
Message-Id: <3649DB40.C90DA9@synopsys.com>
It is not a good practice to remove an element from the array when you are
using foreach loop over that array.
The efficient way to do this to store old and new titles in the hash ( Assosiative
array ).
Hash searching is faster than the linear array search. To check the presence of new
title in
old title, you can use "exists" function.
Hope this help in solving the problem
-- Baliga
Oliver Moffat wrote:
> I'm trying to write a Perl script to automate the updating of a flat text
> file database. I'm trying to compare the new database of titles to the old
> databse of titles and get a list of "Brand New Titles."
>
> Everything goes fine up untill the following chunk of code where the
> actual comparison is supposed to happen. When the script gets to this
> point it gets stuck and just spins its wheels. Is there an infinite loop
> here? Is there a more efficient way to do this?
>
> while (@new_titles)
> {
> $i = shift (@new_titles); # grab the title on the top
>
> $j = 0;
>
> foreach $k (@old_titles) # compare the new title to each
> of the old titles
> {
> if ($i eq $k) # untill we find a match
> {
> splice (@old_titles, $j, 1); # remove the matched title from
> the old titles list
> last; # so we don't check
> it again and stop looking
> }
> elsif ($#old_titles < 1) # but if we're at the end of
> the list of old titles
> { # then we found a
> brand new title
> push (@brand_new_titles, $i); # so we push it onto brand_new_titles
> }
> else # if we don't find a
> match
> {
> $j++; # increment the
> counter and keap looking
> }
> }
> }
------------------------------
Date: Wed, 11 Nov 1998 11:45:51 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: ronald_f@my-dejanews.com
Subject: Re: concurrently writing to a file without doing flock
Message-Id: <3649CD4F.A5FB22E1@email.sps.mot.com>
[Posted to comp.lang.perl.misc and copy mailed.]
ronald_f@my-dejanews.com wrote:
>
> In article <3648C98F.83D09948@fccj.org>,
> bill@astro.fccj.org wrote:
> > ronald_f@my-dejanews.com wrote:
> > >
> > > What is the worst thing that can happen when several processes print to the
> > > same file, without using flock, every print writes exactly one line, and the
> > > file handles are set to unbuffered? In particular: Could it be that some
> lines
> > > arrive split into pieces or get lost?
> > >
> > > From the FAQ I conclude that, using autoflush, the buffer is flushed at the
> > > end of each print statement, so I think that no lines should be lost, and
> > > every line is written to the file in one piece. Can someone confirm this?
>
> > You can confirm it yourself.
>
> Actually I tried it, and *never* got inconsistent results. This may be due to
> sheer luck, of course, and that's why I posted this question.
>
> I know that in general one should never concurrently write to a file without
> locking, lest desaster will occur. But IMO, my case is particular to Perl:
>
> Perl guarantees that - for unbuffered file handles - the buffer gets flushed
> automatically at the end of its print statement, so when two Perl processes do
> this concurrently, process A tells the operating system to write line A, and
> process B tells the operating system to write line B. One of these processes
> must be the first, and since output is unbuffered, the operating system takes
> either one of these lines and writes it to the file as a piece, so I
> contemplated that, while the relative sequence of the lines is not
> deterministic, no line should be lost (as Tom Phoenix suspected), and no two
> lines should be garbled together. Please correct at which point my conclusions
> go wrong.
To get a better understanding, you might want to pick up a book on
operating system design and look up for the keyword 'mutual exclusion'.
If you did do it correctlly, then that actually further describe the
danger of such implementation - it doesn't always happen.
Like everyone said, do count on it, I won't.
-tk
------------------------------
Date: Wed, 11 Nov 1998 15:56:54 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: concurrently writing to a file without doing flock
Message-Id: <F29LMu.EM4@world.std.com>
ronald_f@my-dejanews.com writes:
>Perl guarantees that - for unbuffered file handles - the buffer gets flushed
>automatically at the end of its print statement, so when two Perl processes do
>this concurrently, process A tells the operating system to write line A, and
>process B tells the operating system to write line B. One of these processes
>must be the first, and since output is unbuffered, the operating system takes
>either one of these lines and writes it to the file as a piece,
That's assuming that there are no short write() system calls, (a
situation in which not all of the data is sent to the kernel and the
remainder has to be sent in a second call) and that the largest amount
of data sent in a single perl output function is less than the maximum
allowed by write().
A single write() system call is atomic, but that doesn't mean that
perl's print() function is, even with command buffering on.
--
Andrew Langmead
------------------------------
Date: Wed, 11 Nov 1998 12:17:28 -0500
From: "Robert Kennedy" <kennedy_r@hlhont.moh.gov.on.ca>
Subject: Dial-in or local LAN?
Message-Id: <72cgi8$ub$1@news.gov.on.ca>
I am new to Perl, does anyone know how to determine whether a user is
dialing-in (RAS) from home to his NT account, or he is using the LAN
connection right at the office. Do I try to determine the port number that
the client is accessing from the server??
------------------------------
Date: Wed, 11 Nov 1998 17:19:28 GMT
From: pub @ alma . ch (M.)
Subject: Re: e-mail
Message-Id: <3649c5b6.117154478@news.urbanet.ch>
>The previous advice of going with Sendmail is a good idea. We had
>some problems installing sendmail on NT here. We have found that Blat
Unless I missed a message in the thread, the previous advice was quite
the opposite: it was to go with a pure Perl module like Mail::Sendmail
(which may be a confusing name :-) ), or some other one like
Mail::Sender or Net::SMTP, and to avoid command-line mailers like
sendmail, Blat, etc...
Command-line mailers tend to lock you into one platform, and don't
give you all the fine control that Perl modules do (MIME encodings,
Cc: and Bcc: fields, real names in From: field, custom X-Mailer or
other headers or no unwanted headers, etc...).
------------------------------
Date: Wed, 11 Nov 1998 12:03:36 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: jkane@my-dejanews.com
Subject: Re: Emulate dirname and basename in perl??
Message-Id: <3649D178.20B272CC@email.sps.mot.com>
[Posted to comp.lang.perl.misc and copy mailed.]
jkane@my-dejanews.com wrote:
>
> In article <727v5a$1o8$1@news-2.news.gte.net>,
> Dennis Moreno <dennis.moreno@safetran.com> wrote:
> > Hi-
> >
> > I'm lookin for an example of emulating the unix "basename" and "dirname"
> > commands
> > using perl. Anyone have an example they'd like to share?
>
> I use this for basename ...
>
> $0 =~ s#.*/##;
>
> Not sure if it works in ALL instances yet, but it seems to work so far.
use File::Basename;
it support different systems.
-tk
------------------------------
Date: 11 Nov 1998 12:09:26 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Hash help
Message-Id: <x7u3069mwp.fsf@sysarch.com>
>>>>> "DG" == Daniel Grisinger <dgris@rand.dimensional.com> writes:
DG> ${ $line{'foo'} } [0] = ' this is some data ';
DG> for ( ${ $line{'foo'} } [0] ) {
DG> s/^\s*//;
DG> s/\s*$//;
DG> $status1 = do_something ($_);
DG> $status1 = do_something_else ($_);
DG> }
my preference is to use a named variable in most cases. it gives more
context about what you are munging. so the only time i use $_ is in map
and grep. nothing wrong with either way, i just like to have names for
every thing.
the for style loses for me when there is only one value and it is only a
trick to set $_. i just assign it to a named var.
if extreme efficiency is an issue, i might use the for trick with a
named var since it aliases the var and doesn't do an extra assignment.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Wed, 11 Nov 1998 12:46:45 -0600
From: Dan Baker <dtbaker-@busprod.com>
Subject: help explain a regx example?!
Message-Id: <3649DB95.A7B3B71A@busprod.com>
a while back, Tom C. posted an example that almost does what I need for
a little subsitution subroutine, but I am struggling with a regx he
uses. I need to really understand it so I can make the alterations for
what I'm doing. If you would care to add some annotations on what the
regx is doing line by line I sure would find it educational...
here is the section I need help with:
# replace quoted words with value in %$fillings hash
$text =~ s{ %% ( .*? ) %% } # put a matched quoted word into $1,
# but, in the "( .*? )" why is the ? there?
{ exists( $fillings->{$1} ) # this expression is killing me...
? $fillings->{$1} # what is the significance of using curly {$1}?
: "" # and what is the exists()?: doing?
}gsex; # g=global, s=treat as single line,
# e=causes second part to eval as expression
# rather than string, x=allows whitespace in expression
the full example is:
-------------------
>From the Perl Cookbook:
To expand only variable references, use this template() function:
%fields = (
username => $whats_his_name,
count => $login_count,
total => $minute_used,
);
print template("/home/httpd/templates/simple.template", \%fields);
sub template {
my ($filename, $fillings) = @_;
my $text;
local $/; # slurp mode (undef)
local *F; # create local filehandle
open(F, "< $filename") || return;
$text = <F>; # read whole file
close(F); # ignore retval
# replace quoted words with value in %$fillings hash
$text =~ s{ %% ( .*? ) %% }
{ exists( $fillings->{$1} )
? $fillings->{$1}
: ""
}gsex;
return $text;
}
On a data file like this
<!-- simple.template for internal template() function -->
<HTML><HEAD><TITLE>Report for %%username%%</TITLE></HEAD>
<BODY><H1>Report for %%username%%</H1>
%%username%% logged in %%count%% times, for a total of %%total%%
minutes.
--
Thanx, Dan
# If you would like to reply-to directly, remove the - from my username
* no spam please... regulated by US Code Title 47, Sec.227(a)(2)(B) *
------------------------------
Date: Wed, 11 Nov 1998 13:53:02 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Help please - Testing if a substring in a certain position is equals to
Message-Id: <alecler-1111981353020001@dialup-748.hip.cam.org>
In article <3649B04D.7ACB@stud.uni-sb.de>, Godfrey McLean
<gomc0000@stud.uni-sb.de> wrote:
> I am learning Perl and using it in a project.
>
> I would like to test if a substring in a specific position is equals to
> a certain string - i.e. if character 2 and charter 3 = to "hi". I
> cannot seem to find the right solution.
substr($s,1,2) eq 'hi'
For a case-insensitive test, you can write
substr($s,1,2) =~ /hi/i
All the wonderful core functions like substr() are described in perlfunc,
part of the Fine Manual(TM).
HTH,
Andre
------------------------------
Date: Wed, 11 Nov 1998 17:17:37 -0000
From: "Carlos Woodcock" <Carlos.Woodcock@mail.ineti.pt>
Subject: Help with Perl5
Message-Id: <72cgv8$5q1@nuger3.ineti.pt>
hi,
i installed Perl5 and now whem i try to run a .pl on my browser it gives me
this error:
----------------------------------------------------------
HTTP Error 405
405 Method Not Allowed
The method specified in the Request Line is not allowed for the resource
identified by the request. Please ensure that you have the proper MIME type
set up for the resource you are requesting.
Please contact the server's administrator if this problem persists.
----------------------------------------------------------------------------
--------
I have Nt40 server , IIS, and its a Alpha.
can anyone help me to correct this problem ?
check the URL to see the error:
http://www.instituto-europeu.com/efff/curso.htm
thx
carl@mail.ineti.pt
------------------------------
Date: 11 Nov 1998 18:33:34 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: Help with Perl5
Message-Id: <72cl9u$5o6$2@news.cyberhighway.net>
In article <72cgv8$5q1@nuger3.ineti.pt>,
"Carlos Woodcock" <Carlos.Woodcock@mail.ineti.pt> writes:
> hi,
>
> i installed Perl5 and now whem i try to run a .pl on my browser it gives me
> this error:
[snip "method not allowed" error]
> I have Nt40 server , IIS, and its a Alpha.
I'll bet you could get a lot more help in this area in a newsgroup about
IIS. This is a server problem, not a perl problem.
--
Erik Nielsen, Cyberhighway Internet Services NOC
: I could understand principles of Perl source in 2-3 days [. . .]
Gee, it took me about eleven years. :-)
-- Larry Wall in <199806200201.TAA22277@wall.org>
------------------------------
Date: Wed, 11 Nov 1998 18:14:32 GMT
From: tore@forumnett.no (Tore Aursand)
Subject: Re: help:counting the number of occurences of a specified string in a file
Message-Id: <3649d3b6.610959953@news.online.no>
On Wed, 11 Nov 1998 10:46:22 GMT, bjjgann@liv.ac.uk (bjjgann) wrote:
> I am trying to count the number of times a string appears
> in a given file.
open(FILEHANDLE, "filename.ext");
while (<FILEHANDLE>) {
$hits++ while /string/g;
}
close(FILEHANDLE);
--
Tore Aursand
ForumNett Online AS
<URL:http://www.forumnett.no/>
------------------------------
Date: Wed, 11 Nov 1998 16:03:21 +0100
From: jwl@_munged_worldmusic.de (Joergen W. Lang)
Subject: Re: help:counting the number of occurences of a specified string in a file
Message-Id: <1dic23r.khmwmwh21pfkN@host022-210.seicom.net>
bjjgann <bjjgann@liv.ac.uk> wrote:
> I am trying to count the number of times a string appears
> in a given file.
>
> So far I have managed to count the number of occurences on a particular line,
> the number of the line where the string occurs, and just about any other
> combination you care to imagine, except for the result I want.
>
> Is this an easy 3 liner, which am just missing or is it more complex.
> Any advice would be appreciated.
>
> B Gannon
here's one way to do it:
#!/usr/bin/perl -w
$file = "foo/bar/baz.data";
$matchme = "mooof";
$num = 0;
$count = 0;
open FILE, $file or die "Can't open $file: $!";
while (<FILE>)
{
if (/$matchme/)
{
$num = s/$matchme//g;
$count += $num;
}
}
close FILE;
print "$matchme found $count times."
__END__
hth,
Joergen
--
To reply by email please remove _munged_ from address Thanks !
-------------------------------------------------------------------
"Everything is possible - even sometimes the impossible"
HOELDERLIN EXPRESS - "Touch the void"
------------------------------
Date: Wed, 11 Nov 1998 18:44:39 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: How do I sort this list by "port" number?
Message-Id: <rWk22.6177$fS.20330733@news.itd.umich.edu>
In article <MPG.10b2d014c94a41e6989904@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>[Posted to comp.lang.perl.misc and copy mailed.]
That's really not necessary. In fact, it's annoying.
>In article <O6822.6038$fS.19967516@news.itd.umich.edu> on Wed, 11 Nov
>1998 04:10:22 GMT, Sean McAfee <mcafee@waits.facilities.med.umich.edu>
>says...
>> In article <72avp0$n0j$1@nnrp1.dejanews.com>, <munn@bigfoot.com> wrote:
>> >I am wanting to sort ONLY by the first numbers in the "line", in this case,
>> >the number is the "port", and I want to sort based on this. any way to do
it?
>> >I can't figure it out, sort doesn't work very well at all...
>> No, actually it works very well.
>I think it works very poorly, because it is not '-w' clean, and all
>programs should run with '-w' enabled at all times!
I disagree. And anyway, by "it" I and the original poster were referring
to Perl's sort function, not my particular algorithm.
>> @sorted_a = sort { $a <=> $b } @a;
>> This is the same way one sorts lists of numbers, and it works here becasue
>> when each line is treated as a number, it turns into your port number.
>But these are not lists of numbers. They are strings that begin with
>numbers.
Given Perl's automatic conversion between strings and numbers, the
difference is academic. Er, mostly academic, as my solution has the
overhead of repeated string-to-number conversions, but it's still much
faster than your solution, as shown below.
If you must have warnings enabled, just localize $^W around the appropriate
code.
>Let's roll out the Schwartz Transform:
>
> @sorted_a = map $_->[0],
> sort { $a->[1] <=> $b->[1] }
> map { [ $_, /(\d+)/ ] } @a;
Let's not. The ST is overkill for this problem. Perl's string converion
behavior is exactly what's wanted here; why refuse to take advantage of it?
----------------------------------------------------------------------
use Benchmark;
$^W = 1; # turn on warnings
open(WORDS, "/usr/dict/words") || die "Can't open words: $!\n";
@words = map sprintf("%d %s", int(rand(1000000)), $_), <WORDS>;
close(WORDS);
timethese(30, {
'simple' => sub { local $^W; @a = sort { $a <=> $b } @words },
'schwartzian' => sub { @a = map $_->[0], sort { $a->[1] <=> $b->[1] }
map { [ $_, /(\d+)/ ] } @words }
});
----------------------------------------------------------------------
Benchmark: timing 30 iterations of schwartzian, simple...
schwartzian: 91 wallclock secs (89.37 usr + 0.08 sys = 89.45 CPU)
simple: 31 wallclock secs (30.97 usr + 0.00 sys = 30.97 CPU)
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Wed, 11 Nov 1998 11:01:45 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Installing a Perl module to Active Perl
Message-Id: <3649C2F9.E3822CBA@us.ibm.com>
Damon Register wrote:
>
> All of the installation instructions for Perl modules that I have
> seen so far seem to be written for unix systems and don't
> cover the PC world. They all use a make command
> that is not on my system. Is there a make for PCs or is there
> some other way of installing Perl modules in the PC world?
ActiveState uses a program called ppm to install modules. Check
DejaNews for more details. Don't forget to check the modules group also
(using DejaNews).
--
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)
------------------------------
Date: Wed, 11 Nov 1998 17:01:33 GMT
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: Installing a Perl module to Active Perl
Message-Id: <3649C2ED.7FA559AF@technologist.com>
Damon Register wrote:
>
> All of the installation instructions for Perl modules that I have
> seen so far seem to be written for unix systems and don't
> cover the PC world. They all use a make command
> that is not on my system. Is there a make for PCs or is there
> some other way of installing Perl modules in the PC world?
>
> I tried the Active State Perl web site but found nothing on
> this subject. The help that comes with ActivePerl mention
> installation but the distribution is missing the html file for this
> information.
>
> Damon Register
Take a look at:
http://www.activestate.com/ActivePerl/docs/description.html#perl_package_manager
ActiveState included a utility called Perl Package Manger in your
distribution that handles installing modules.
Good luck!
Brent
--
Java? I've heard of it, it is what I drink when I am hacking Perl. -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$ Brent Michalski $
$ -- Perl Evangelist -- $
$ E-Mail: perlguy@technologist.com $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
------------------------------
Date: Wed, 11 Nov 1998 17:52:35 GMT
From: Rafely@xxiname.com
Subject: Is this possible using the truncate command
Message-Id: <3649c87b.2021026@news.iaehv.nl>
Hello,
I'm making a form that writes the form data to a text file instead of
e-mailing me the results. But I don't want the file to exceed 25kb.
What I want to do is write new data at the begin of the file so the
oldest data will be at the end. When the file exceeds 25kb I want to
delete a few lines from the bottom of the file (where the old data are
stored) so that the file is 25kb again. My guestion is, is this
possible with the truncate command? I was thinkng something like this:
(please look at the idea and not at the errors in the script)
open (FILE, "text.txt");
@database = <FILE>;
close (FILE);
&Get_new_data;
open (FILE, ">text.txt");
print FILE "$newdata";
foreach $line (@Database) {print FILE "$line";}
close(FILE);
truncate(FILE,25000);
Will this do what I described above?
Many Thanks
Rafely
------------------------------
Date: 11 Nov 1998 17:56:47 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: Is this possible using the truncate command
Message-Id: <72cj4v$33c$1@news.cyberhighway.net>
In article <3649c87b.2021026@news.iaehv.nl>,
Rafely@xxiname.com writes:
[snip]
> Will this do what I described above?
You could always try it and find out.
Oh, and if you want 25k, 25600 is more accurate than 25000
HTH!
--
Erik Nielsen, Cyberhighway Internet Services NOC
I suppose one could claim that an undocumented feature has no
semantics. :-(
-- Larry Wall in <199710290036.QAA01818@wall.org>
------------------------------
Date: Wed, 11 Nov 1998 08:46:29 -0800
From: "Randy O'Meara" <randy.omeara@lmco.com>
Subject: Passing Perl Hash Through DCOM
Message-Id: <72cf17$31m$1@lscruz.scf.lmms.lmco.com>
I wish to construct an Automation Object (call it SERVER) in Perl that will
return a data structure that is not a simple scalar value. In particular, I
want the SERVER to return a Perl hash to the activating client (call it
CLIENT).
In order to keep it simple, the CLIENT that uses this object (through DCOM)
will also be written in Perl. As an alternative to SERVER returning a hash,
a hash could be passed by reference from CLIENT to SERVER who would then
return information in this passed variable.
I have read, searched, and browsed all of the resources I am aware of
(including the Perl Win32 RK), and cannot find information on passing a
non-scalar return value from SERVER to CLIENT. The PerlCtrl documentation
provides sample code that uses scalar values, but no arrays or hashes.
Do one of you kind folks have a code sample that performs this task? How
about a pointer to reference material that covers this subject?
Thank you,
Randy O'Meara
------------------------------
Date: Wed, 11 Nov 1998 18:46:35 GMT
From: "News" <dixonmat@pouch.com>
Subject: Re: percentages
Message-Id: <fYk22.91$5v3.805616@news.optonline.net>
I am not familiar with this -w tag you are reffering to, but here is the
monify section
sub Monify
{
$in = $_[0];
if (!$in) { $in = 0.00; }
if ($in =~ /\.00/) { return $in; } # It already has zero cents
if ($in !~ /\./) { return "$in.00"; } # Add two zeros for cents
# Truncate the cents to two digits; Must round up if necessary
else
{
@in = split (/\./, "$in");
$dollars = @in[0];
$cents = ".@in[1]" * 100;
@cents = split (/\./, "$cents");
$cents = @cents[0];
# see if the next digit is >= 5 to round up
$nextDigit = ".@cents[1]" * 10;
@nextDigit = split (/\./, "$nextDigit");
$nextDigit = @nextDigit[0];
if ($nextDigit >= 5) { $cents++; }
if ($cents <= 9) { $cents = "0$cents"; }
return "$dollars.$cents";
}
basically the monify routine sets the monitary value
}
------------------------------
Date: Wed, 11 Nov 1998 13:28:22 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Perl class question
Message-Id: <3649D746.73EC3DB7@min.net>
xaqtnr@my-dejanews.com wrote:
>
> package SystemVars;
>
> sub new{
> my $class = shift;
> my $self = { };
> bless ($self, $class);
> $self->{df} = { };
> return $self;
> }
O.k., but how about:
sub new {
my $class = shift;
bless {
df => { },
}, $class;
}
> sub df{
> my $self = shift;
> @data = `df`;
> shift(@data);
> while (@data){
> $line = shift(@data);
> $line =~ s/\s+/ /g;
> ($file_sys,$k_blocks,$used,$avail,$capacity,$mounted_on)
> = split (/ /,$line);
> $self->{df}->{FILE_SYS} = $file_sys;
> $self->{df}->{K_BLOCKS} = $k_blocks;
> $self->{df}->{USED} = $used;
> $self->{df}->{AVAIL} = $avail;
> $self->{df}->{CAPACITY} = $capacity;
> $self->{df}->{MOUNTED_ON} = $mounted_on;
> }
> return $self;
> }
>
>
> #!/usr/bin/perl5
> use SystemVars;
>
> $vars = SystemVars->new();
> $fs = $vars->df(FILE_SYS);
> print"FS => $fs<br>";
>
> This gives me the following: FS => SystemVars=HASH(0x74048)
Of course it does. You're calling the df subroutine, and
printing what it returns. You have defined it to return
the object ($self). You can clear up that problem right
away by changing that call to this:
$fs = $vars->{df}->{FILE_SYS};
However, it seems to me that you've got deeper problems than that.
Specifically, the code in sub df goes through each line of the
output from `df`, splits it, and puts it into the 'df' field of the
object. It does this repeatedly. So in the end, the object only
contains the info for the very last line of the output from `df`.
Is that what you wanted?
Also, that while loop could be simplified by doing this:
my @data = `df`;
shift @data;
foreach ( @data ){
my($file_sys,$k_blocks,$used,$avail,$capacity,$mounted_on)
= split;
$self->{df}->{FILE_SYS} = $file_sys;
# etc.
Does your command line include the -w switch?
I suggest you make all your variables 'my' variables, as much as
possible. You should also try to make your program complile
cleanly under 'use strict', which encourages good programming
habits.
--
John "Throbblefoot" Porter
Please Don't "Courtesy CC" me.
I read this newsgroup fanatically. You know that!
("Emailed only" is fine, though.)
"The people at the Grey Hotel
Are either aged or unwell." -- EG
------------------------------
Date: Wed, 11 Nov 1998 10:01:56 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Andrew Johnson <ajohnson@gatewest.net>
Subject: Re: PERL is TOO flexible
Message-Id: <3649D114.7782699@atrieva.com>
Andrew Johnson wrote:
> I don't know why people always insist on programs being readable by
> those who don't know, or are new to, the given language --- sure, its
> a mark of readability if a programmer unfamiliar with language X can
> read language X to some degree ... but, come on, language X was
> designed to be read by language X programmers---people who have
> learned at least something about language X. I'm sure German is
> perfectly readable to those who know German, but is it more or
> less readable than English?
I would go so far as to say that for any given non-perl programmer, perl
is far more readable than most other languages. I try to write
maintainable code, knowing that the person maintaining it behind me
might not be so perly. It's a great language as far as that goes.
--
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947
The Atrieva Service: Safe and Easy Online Backup http://www.atrieva.com
------------------------------
Date: Wed, 11 Nov 1998 11:55:02 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: PERL is TOO flexible
Message-Id: <3649CF76.B0B17A69@email.sps.mot.com>
Anita M Wilcox wrote:
>
> In article <82k91b1dlp.fsf@shell2.shore.net>, Jay Rogers <jay@rgrs.com> wrote:
> >Brent Michalski <perlguy@technologist.com> writes:
> >
> >> In article <3638676E.F980FC4A@harris.com>,
> >> PERL ROCKS! <emills@harris.com> wrote:
> >> > "Although the Perl Slogan is There's More Than One Way to Do It, I
> >> > hesitate to make 10 ways to do something. :-) "
> >> > --Larry Wall in <9695@jpl-devvax.JPL.NASA.GOV>
> >> >
> >> >is along these lines- why make more than ONE? What did it add, Larry?
> >>
Well, if Perl had only one way of doing thing, I wouldn't be reading
this newsgroup now. That's eaxctly where the fun is - more than one way!
-tk
------------------------------
Date: Wed, 11 Nov 1998 13:54:57 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Perl5 Win32::ODBC SQL Statement Involing dates
Message-Id: <linberg-1111981354570001@ltl1.literacy.upenn.edu>
In article <3644c1fb.0@news.pacifier.com>, "Carl Brink"
<strat@centralnet.net> wrote:
> SQL Error
> [-3010] [2] [0] "[Microsoft][ODBC dBase Driver] Too few parameters.
> Expected 1." at C:\Perl\perldev\chkhour.pl line 136.
This usually means you misspelled a field in your SELECT statement, or
tried to refer to a field that doesn't exist.
_____________________________________________________________________
Steve Linberg National Center on Adult Literacy
Systems Programmer &c. University of Pennsylvania
linberg@literacy.upenn.edu http://www.literacyonline.org
------------------------------
Date: 11 Nov 1998 12:14:28 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: pwd without backticks?
Message-Id: <x7r9va9mob.fsf@sysarch.com>
>>>>> "T" == Thomas <nouser@nohost.nodomain> writes:
T> If this kind of thing matters to a UNIX program, it should know how to
T> deal with it. In modern versions of UNIX, in the presence of NFS
T> automounts and symlinks, in fact, there are lots of other potential
T> problems callers of "pwd" have to deal with anyway.
thanx for the backup. i thought ilya was way off with the claim that pwd
runs suid many places. as you said, historically it has never been an
guaranteed operation. even perl's Cwd module has 3 methods which differ
in how they attempt to do it. and your example of breaking even a suid
pwd is good. as i said and you agree, "caveat programmer".
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Wed, 11 Nov 1998 17:31:36 GMT
From: normingj@taz.dera.gov.uk (James Normington)
Subject: Roaming Profiles on Win32
Message-Id: <3649c60f.619018241@trog.dra.hmg.gb>
Does anyone know if you can set a users profile string using the Win32
extensions. It is not mentioned in any of the Win32 interfaces that I
can find although some bits are (ie NetUser and NetMisc)
I can set it at the moment using 'User Manager for Domains' but I
would like to be able to set/update it from within a perl script.
thanks in advance for any help
James
------------------------------
Date: Wed, 11 Nov 1998 17:06:16 GMT
From: bigcheese@my-dejanews.com
Subject: Re: String Split Help
Message-Id: <72cg68$uhn$1@nnrp1.dejanews.com>
In article <s67b27.9mf.ln@flash.net>,
tadmc@flash.net (Tad McClellan) wrote:
> bigcheese@my-dejanews.com wrote:
> You should not try and type in code. You should use cut/paste.
That WAS copied and pasted! ^_^
Thanks for your help!
-Dan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Wed, 11 Nov 1998 14:20:28 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: String Split Help
Message-Id: <alecler-1111981420280001@dialup-748.hip.cam.org>
In article <s67b27.9mf.ln@flash.net>, tadmc@flash.net (Tad McClellan) wrote:
> bigcheese@my-dejanews.com wrote:
> : Is it possible to make it split "cow "(w/ space) to "co" and "w "?
>
>
> @kana = $ENV{'QUERY_STRING'} =~ /([^aeiou ]*[aeiou ])/g;
How about split /(?=[^aeiou ])/ ?
Andre
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 4198
**************************************