[23055] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5276 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 26 21:05:42 2003

Date: Sat, 26 Jul 2003 18:05:07 -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, 26 Jul 2003     Volume: 10 Number: 5276

Today's topics:
    Re: "theory vs practice" ceases power (Xah Lee)
        [OT] Re: reference symbol not found with UDUNITS <pinyaj@rpi.edu>
    Re: Called as method or subroutine? <mgjv@tradingpost.com.au>
        can this one-liner be squeezed any shorter? <jidanni@jidanni.org>
    Re: document ID tracking <asu1@c-o-r-n-e-l-l.edu>
    Re: FTP in ASCII mode from UNIX to NT <someone@somewhere.nl>
        Help needed with basic Perl math commands <ducott@hotmail.com>
    Re: Help needed with basic Perl math commands <noreply@gunnar.cc>
    Re: Help needed with basic Perl math commands <jurgenex@hotmail.com>
        I lost my 'perl' file. Where can I get it? (Francesco Moi)
    Re: I lost my 'perl' file. Where can I get it? <dorward@yahoo.com>
        Need help chopping data in Perl <ducott@hotmail.com>
    Re: Need help chopping data in Perl <noreply@gunnar.cc>
    Re: Need help chopping data in Perl <jurgenex@hotmail.com>
        Newbie Question <>
    Re: Newbie Question <noreply@gunnar.cc>
    Re: Pesky added line <nospam@xx.com>
    Re: Simple site index <a@ry.ca>
    Re: Tracking Number (Jeff Mott)
        use File::Archive extracting zip's with '.' in front of (david)
    Re: XML or home-grown format? <julian@avbrief.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 26 Jul 2003 11:45:08 -0700
From: xah@xahlee.org (Xah Lee)
Subject: Re: "theory vs practice" ceases power
Message-Id: <7fe97cc4.0307261045.6f442296@posting.google.com>

Dear Dave Benjamin,

You wrote:
 [morons are just joking with their "theroy vs practice" quote]

I have written the following essay, that i hope will demystify the
computing jockey's inquiring minds.

from:
 http://xahlee.org/UnixResource_dir/writ/theory_practice2.html

-- begin quote --
From: Xah Lee
Date: Wed, 8 May 2002 22:01:25 -0700

When the theory and practice type of mind-tickling word-playing quotes
are quoted by the Perl and unix morons, there exudes a subtle
implication, an indifference, that seems to suggest that there truly
lies a logical wisdom that dismisses computer science or formalism
being overrated. All is allright in the world, except that these
Perlers and unixers's minds are tainted by such unconscious
affirmation to yield stupider and stupidier mode of thinking on
computing, from programing languages to software methodologies. Thusly
their "there is more than one way to do it" type of creeds become
lodged firmly in these folks' minds as an unconventional but sound
alternative principles, maiming themselves notwithstanding but harming
the society and young by hegemony. These $Free$ and "Freedom" type of
morons hog onto free things and rolls like a blackhole, sucking up
poor students and encroaching the computing industry, to the degree
that obvious falsities are being conceived as indubitable truths.

Last week i bought a chain-saw with a twisted handle. Perhaps i wasn't
careful, but by accident it chopped one of my arm off, then i thought
to myself "gosh, this is POWERFUL!". This seems to be the fashionable
mode of thinking among the unixers or unixer-to-be, who would equate
power and flexibility with rawness and complexity; disciplined by
repeated accidents. Such a tool would first chop off the user's brain,
molding a mass of brainless imbeciles and microcephalic charlatans the
likes of Larry Wall and Linus Torvald jolly asses.

next time you hear someone quoting theory and practice, please
secretly take a glance at their smugness, then snicker at these folk's
stupor. If you are a kind man, point them to my opuses.

-- end quote --

I have a tome about the tremendous harm irresponsible programers has
done to the computing industry that i need to write. Right now, they
exists as slipshod semi-cogent harangues scattered around my Unix
Pestilence website. (http://xahlee.org/UnixResource_dir/freebooks.html)

Writing a authoritave book or commanding a sweeping revolution in
computing is not easy. I'm trying to form my comprehensive thesis in
bits and pieces. Occational postings begets feedback that allows me to
see the minds of the coding drone and mostly incite incentive to
continue my work. I'm delighted to receive questions. As of recent
i've thought of writing a Unix FAQ that answers common objections to
my unix criticizing essays. I very much welcome questions. I cannot
guarantee to answer them individually, but the well thought out and
sincere ones i'll try to reply singly.

If you support education and support my work, please execuse some of
my rambling mannerism or foibles. There is a coherent and
comprehensive presentation in the plan. Meanwhile, i know many of you
are in the same school of mine well represented by Edsger W Dijkstra.
I wish us sally forth and be absolutely belligerent about correct,
quality, and most importantly RESPONSIBLE programing pratices in the
computing industry, and go all out to eliminate charlatans and their
pretenses.

----

Software is a interesting invention. Software has this interesting
property, that it can be duplicated without cost, as if like copying
money. Never in history are goods duplicable without cost. But with
the invention of computer, the ephemeral non-physical programs breaks
that precept. In digital form, program and music and books all become
goods in essentially infinite quantity.

All is good except, bads in digital form can also multiply equally,
just as goods. Wellk nown examples are computer viruses and email
spams. Unknown to the throng of unix morons is software bads. In a
unix moron's mind, the predominant quip among hackers is "where is
your code?", singnifying the mentality that a hacker's prestige is
judged on how much code he has contributed to the community.
Therefore, every fucking studs and happy-go-lucky morons put their
homework on the net, with a big stamp of FREE, and quite proud of
their "contributions" to the world. These digital bads, including
irresponsible programs, protocols, and languages, spread like viruses
until they obtained the touting right of being the STARDARD or MOST
POPULAR in industry, as if indicating superior quality. Examplary are
C, Perl, RFC, X-Windows, Apache, php (and almost anything out of
unix). The harm of a virus is direct. The harm of irresponsible
software (esp with unscrupulous promotion) is the creation of a entire
generation of bad thinking and monkey coders. The scales can be
compared as to putting a bullet in a person brain, versus creating a
creed with the Holocaust aftermath.

Distribution of software is easily like pollution. I thought of a law
that would ban the distribution of software bads, or like charging for
garbage collection in modern societies. The problem is the difficulty
of deciding what is good and what is bad. Like in so many things, i
think the ultimate help is for people to be aware; so-called
education; I believe, if people are made aware of the situation i
spoke of, then irresponsible software will decrease, regardless any
individual's opinion.

--

Addendum: planned essays in the immediate future is the Unix FAQ as
mentioned before, and also i've been thinking of an essay along the
lines of _In Praise of Microsoft_, because recently it occured to me
that Microsoft has inargurated a few things that i consider the
antidote to the IT industry quagmire, namely the creation of
Certification system for computing professionals, and recently on the
news the creation of a responsible licensing scheme that makes the
software producer liable for damages caused by their product.

The most important measure to counter the tremendous harm that
irresponsible software has done to the industry is to begin with
responsible license, such that the producer of a software will be
liable for damage incurred thru their software. As we know, today's
software licenses comes with a disclaimer that essentially says the
software is sold as is and the producer is not responsible for any
damage, nor guaranteeing the functionality of the software. It is
this, that allows all sorts of sloppitudes and fucking fads and myths
to rampage and survive in the software industry. Once when software
producers are liable for their products, just as bridge or airplane or
transportation or house builders are responsible for the things they
build, then injurious fads and creeds the likes of (Perl, Programing
Patterns, eXtreme Programing, "Universal" Modeling Language...) will
automatically disappear by dint of market force without anyone's
stipulation.

In our already established infrastructure of software and industry
practices that is so already fucked up by existing shams, we can not
immediately expect a about-face in software licenses from 0 liability
to 100% liability. We should gradually make them responsible. And
this, comes not from artificial force, but gradual establishment of
awareness among software professionals and their consumers. (Producers
includes single individual to software houses, and consumers includes
not just mom & pop but from IT corps to military.)

The OpenSource movement (including FreeSoftware), has its merits and
demerits as to economy, but i should point out that by its sharing and
altruistic and often authorless nature the software produced by
OpenSource tends to have no one to take responsibity for. If we want
the OpenSource to be taken seriously, its enterprises must also
gradually steps into a license with liabilities.

 Xah
 xahlee.org
 http://xahlee.org/PageTwo_dir/more.html


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

Date: Sat, 26 Jul 2003 17:25:02 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: [OT] Re: reference symbol not found with UDUNITS
Message-Id: <Pine.SGI.3.96.1030726172428.221268A-100000@vcmr-64.server.rpi.edu>

Am I the only one who reads "UDUNITS" as "(wh)o-dun-its"?

-- 
Jeff Pinyan            RPI Acacia Brother #734            2003 Rush Chairman
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Sun, 27 Jul 2003 10:51:23 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Called as method or subroutine?
Message-Id: <slrnbi68gb.rlm.mgjv@martien.heliotrope.home>

On 26 Jul 2003 06:13:12 GMT,
	Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
> Also sprach Martien Verbruggen:
> 
>> On 24 Jul 2003 06:21:58 GMT,
>> 	Tassilo v. Parseval <tassilo.parseval@rwth-aachen.de> wrote:
>>> Also sprach Martien Verbruggen:
> 
>>>> The notation MyClass::mySub() is not subject to inheritance in any
>>>> way. In other words, the above two calls cannot be equivalent, because
>>>> of Perl's magical treatment of that arrow. If you use that arrow, Perl
>>>> will search through @ISA. If you don't, then it won't.
>>> 
>>> Which, as far as I understand, was Eric's point.
>> 
>> The point that I was trying to make is that with a call like
>> MyClass::mySub() it is not even really possible to talk about
>> inheritance, since it's not a method call, but rather a regular
>> subroutine call, and therefore never subject to Perl's inheritance
>> mechanisms.  You do need the arrow for that. 
> 
> Hmmh, just a sec. Plain functions are subject to inheritance in Perl
> (they also trigger AUTOLOAD if it exists):
> 
>     ethan@ethan:~$ perl -l
>     package t;
>     require CGI;
>     @ISA = qw/CGI/;
>     package main;
>     print t::h1("test");
>     __END__
>     <h1>test</h1>
> 
> That makes class-methods and function look even more indistinguishable.

$ cat /tmp/foo.pl
use strict;
use warnings;

package Foo;
sub foo { print "Foo::foo called\n"; }

package Bar;
@Bar::ISA = qw/Foo/;

package main;
Bar->foo();
eval { Bar::foo() };
print "$@" if $@;
eval { Bar::foo("Bar") };
print "$@" if $@;
eval { Bar::foo("Foo") };
print "$@" if $@;
# Indirect syntax:
Bar::foo Bar;

$ perl /tmp/foo.pl
Foo::foo called
Undefined subroutine &Bar::foo called at /tmp/foo.pl line 12.
Undefined subroutine &Bar::foo called at /tmp/foo.pl line 14.
Undefined subroutine &Bar::foo called at /tmp/foo.pl line 16.
Foo::foo called

I don't know what extra work CGI.pm does, but to me that looks like @ISA
does not come into play unless the arrow notation is used (ignoring the
horror of indirect calling).

Martien
-- 
                        | Yes; Windows is great for running &
Martien Verbruggen      | developing viruses, for instance.  It's also
                        | very popular, but then again, so is the
                        | common cold. -- Dave Hinz


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

Date: Sun, 27 Jul 2003 08:32:01 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: can this one-liner be squeezed any shorter?
Message-Id: <87oezgreri.fsf@jidanni.org>

Say, can this one-liner be squeezed any shorter, aside from removing
spaces or hardwiring $q's value?
perl -anlwe 'BEGIN{$q=7.2*3600};printf "%4d %s\n",$q/shift @F,"@F"'
Reference: http://jidanni.org/geo/taipower/meter_en.html


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

Date: 26 Jul 2003 19:45:17 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: document ID tracking
Message-Id: <Xns93C4A044A8D34asu1cornelledu@132.236.56.8>

satishi@gwu.edu (slash) wrote in
news:30fe9f1e.0307260943.1f4352b1@posting.google.com: 

> Thanks so much for all the helpful responses. (Sinan, this is not a HW
> problem! :) I didn't get any helpful responses in another related
> postiing so I am adding this as a followup here hoping that it will
> get reviewed.

You'll need to post something that can be run locally (make sure some 
sample input data are included).

 ...
 
> undef $/;

Are you sure you want to this here?

>         my @words = split /\W+/, <> ;
>         my $line_number = 2;
>         my $n;
>         my $line_num = 2;

What is the difference between $line_number and $line_num and what purpose 
do they serve?

>         my $n_cols = 5;
>         my $col = { align => 'left'}; # no title, left alignment
>         my $tb = Text::Table->new( ( $col) x $n_cols);
>         my @stack = ( '*' ) x $n_cols;
>         foreach $word ( @words ) {
>             shift @stack;
>             push @stack, $word;
>             $tb->add(@stack);
>     } 

What on earth is going on in here?

> my @lines = $tb->add("$stack[-4]", "$stack[-3]", "$stack[-2]",
> "$stack[-1]", "*");
> my @lines = $tb->add("$stack[-3]", "$stack[-2]", "$stack[-1]","*",
> "*");
> my @lines = $tb->table($line_number, $n);

Why do you keep redeclaring and redefining @lines before you do anything 
with it?

> #print @lines;
> my $t1 = $tb->select(2, {is_sep => 2, body => "  "}, 1,0, 
>                         {is_sep => 2, body   => "\n"}, 
>                      2, {is_sep =>2, body => "  "}, 3,4);
> #foreach $textID (@textID) {
> #$t1 = $t1->add($ARGV); }#adds one data line at the end of ngrams not
> a col

I do not understand this comment. Is it supposed to do something else? Did 
you read the docs for Text::Table?

add() 
adds a data line to the table, returns the table. 

> my $input = $t1->table($line_num, $n);
> print $input;
 ...
> To recap, I don't know if I really need an inverted index. Perhaps an
> array of arrays might help instead of the table module. Where I can
> have @lines and $ARGV. Would that work? In other words, an array
> consisting of the following:(first line of ngram, $ARGV)
> (Second line of ngram, $ARGV)
> .
> .
> .
> (Last line of ngram, $ARGV)
> And perhaps I could put this into a table and do the select statemetns
> over them to display the desired output. Is this possible or I am just
> dreaming?

No, you are just rambling. The way this works is, you post a specific 
problem, and people try to help you solve it. We cannot figure out for you 
your requirements etc because we do not have the information you have 
regarding the overall picture.

So, I do not know why you decided the previous solutions we posted to the 
problem of associating each word with the file(s) it came from were 
inadequate. Before people can help you, you have to clearly communicate 
what problem you are trying to solve.

> Any suggestions on how to achieve this would be very much appreciated.

I do not know what you mean by "this". But, would the following help? 

# fubar.pl

use strict;
use warnings;

use Text::Table;

my $cols = 5;
my $col = { 'align' => 'left' };
my $table = Text::Table->new(($col) x $cols);

{
	local $/;
	while(my @words = split /\W+/, <ARGV>) {
		while (@words) {
			my @row = splice (@words, 0, $cols - 1);
			if(@row < $cols - 1) {
				push @row, (undef)x($cols - @row - 1);
			}
			push @row, ($ARGV);
			$table->add(@row);
		}
	}	
}

print ($table->body());
__END__

C:\Home> cat file1
file1a file1b
file1c
file1d
file1e file1f
file1g

C:\Home>cat file2
file2a
file2b
file2c
file2d
file2e
file2f

C:\Home>fubar.pl file1 file2
file1a file1b file1c file1d file1
file1e file1f file1g        file1
file2a file2b file2c file2d file2
file2e file2f               file2

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Sat, 26 Jul 2003 23:48:53 +0200
From: "Stefan" <someone@somewhere.nl>
Subject: Re: FTP in ASCII mode from UNIX to NT
Message-Id: <3f22f6af$0$76455$e4fe514c@dreader8.news.xs4all.nl>

"jiju" <jmkuruvilla@yahoo.com> schreef in bericht
news:c396a971.0307251713.79ca8790@posting.google.com...
> hi,
>
> I can't open up a text file that I FTP'd from UNIX to Windows 2000
> even though I set the type to ASCII mode ($ftp->ascii();). I guess it
> has to do with carriage return character not encoding correctly on
> 2000 machine. Is there any work around to fix this problem so I could
> open this file up in Notepad?? Need to have it in Notepad to use with
> MS Access
>
> thanks,
> jju


Windows text files use CR (= \r) + LF (= \n) as an end-of-line marker, while
Unix just use LF (= \n). So, before you FTP over a text file, change the
end-of-line marker and store everything in a temporary file. Then transfer
the tmp-file as if it was the source file: $ftp->put(tmp-file, source-file).
Make sure to use binary mode (or at least test ascii mode).

FreeBSD has the commands unix2dos and dos2unix which describe what you're
seeing. Perhaps your Unix flavour has it too.

Bye,
Stefan




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

Date: Sat, 26 Jul 2003 23:58:42 GMT
From: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Help needed with basic Perl math commands
Message-Id: <SAEUa.525335$3C2.13799289@news3.calgary.shaw.ca>

Hey everyone, I'm writting a simple script that takes data from a text file
and calculates percentages. Lets call this file "data.txt" In data.txt,
there are some numbers separated by "|" symbols like below:

2000|1800|500

I will open the file and get its data like this:

open (list, "<data.txt") or &error("Unable to open the data file for
reading");
$list=<list>;
close(list);

I will now split the data like this:

chomp ($list);
($total,$bought,$sold)=split(/\|/,$list);

Now I need help writting a set of commands that will calculate the
percentages of this data. I would like to have it in this format:

print "Total was $total";
print "Bought was $boughtpercentage";  # % of $bought vs $total
print "Sold was $soldpercentage";          # % of $sold vs $total

Can someone please help me with the commands to calculate $boughtpercentage
& $soldpercentage. Thanx to all who read or respond. Code examples are
greatly appreciated. TIA!!!

R




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

Date: Sun, 27 Jul 2003 02:14:47 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help needed with basic Perl math commands
Message-Id: <bfv5ij$iv67k$1@ID-184292.news.uni-berlin.de>

"Dandy" Randy wrote:
> Now I need help writting a set of commands that will calculate the 
> percentages of this data. I would like to have it in this format:
> 
> print "Total was $total";
> print "Bought was $boughtpercentage";  # % of $bought vs $total
> print "Sold was $soldpercentage";          # % of $sold vs $total
> 
> Can someone please help me with the commands to calculate
> $boughtpercentage & $soldpercentage.

I'm sure someone can. The question is if someone wants.

You'd better study the relevant docs, such as 
http://www.perldoc.com/perl5.8.0/pod/perlop.html, at give it a try by 
yourself.

Then, if you - contrary to expectation - would encounter difficulties, 
give us some proof that you actually made an own effort. That will 
increase your chances to get help here.

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



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

Date: Sun, 27 Jul 2003 00:54:43 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Help needed with basic Perl math commands
Message-Id: <npFUa.3772$FP5.1566@nwrddc02.gnilink.net>

"Dandy" Randy wrote:
> Hey everyone, I'm writting a simple script that takes data from a
> text file and calculates percentages. Lets call this file "data.txt"
> In data.txt, there are some numbers separated by "|" symbols like
> below:
>
> 2000|1800|500
>
> I will open the file and get its data like this:
>
> open (list, "<data.txt") or &error("Unable to open the data file for
> reading");
> $list=<list>;
> close(list);

So far so good.

> I will now split the data like this:
> chomp ($list);
> ($total,$bought,$sold)=split(/\|/,$list);

Look good, still.

> Now I need help writting a set of commands that will calculate the
> percentages of this data. I would like to have it in this format:
>
> print "Total was $total";
> print "Bought was $boughtpercentage";  # % of $bought vs $total
> print "Sold was $soldpercentage";          # % of $sold vs $total
>
> Can someone please help me with the commands to calculate
> $boughtpercentage & $soldpercentage. Thanx to all who read or
> respond.

Oh come on. That is second or at most third grade math!
How would you do that with paper and pencil? Write it down. Explicitly!
And then just type that formula into your computer.

For the actual syntax check 'perldoc perlop' for the Perl operators.
Hint: multiplication is "*" and division is "/".

jue




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

Date: 26 Jul 2003 14:35:06 -0700
From: francescomoi@europe.com (Francesco Moi)
Subject: I lost my 'perl' file. Where can I get it?
Message-Id: <5b829932.0307261335.7c1de8f2@posting.google.com>

Hello.

Due to an error, I deleted my '/usr/bin/perl' file.

It was build with 'perl-5.8.0-88.i386.rpm'. 

How can I get it?


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

Date: Sat, 26 Jul 2003 23:27:00 +0100
From: David Dorward <dorward@yahoo.com>
Subject: Re: I lost my 'perl' file. Where can I get it?
Message-Id: <bfuvaj$cpk$1$830fa78d@news.demon.co.uk>

Francesco Moi wrote:
> Due to an error, I deleted my '/usr/bin/perl' file.
> It was build with 'perl-5.8.0-88.i386.rpm'.
> How can I get it?

Reinstalling the same RPM file would seem to be the most logical course of
action.

-- 
David Dorward                                     http://david.us-lot.org/


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

Date: Sat, 26 Jul 2003 23:49:25 GMT
From: "\"Dandy\" Randy" <ducott@hotmail.com>
Subject: Need help chopping data in Perl
Message-Id: <9sEUa.527551$ro6.12239594@news2.calgary.shaw.ca>

Hey everyone, I could use some help with the following. I have written a
small Perl emailing program for our company. My script uses a file called
addressed.txt. This file contains names and email addresses separted by a
"|" character. A sample is below: Note the @ symbol is in brackets so this
post ignores the @ symbol and doesnt create a linkable email address.

Jogn Doe|john(@)email.com
Jane Doe|jane(@)email.com

The sending script opens this file and assigns its data to a @ array.

open (list, "<addresses.txt") or &error("Unable to open the data file for
reading");
flock list, 2;
@list=<list>;
close(list);

Later this data is sent to the sendmail module for sending to each
recipient. My boss has said that he doesnt want to send the full name, only
the first name ... so here is the question: How can I chop off the last name
from the name data? The first name and last name are separated by a simple
space. This is how I currently separate the names from the email addresses:

foreach $list (@list) {
chomp ($list);
($name,$email)=split(/\|/,$list);
}

I'm needing a set of commands that will take the variable $name ... and
remove any data that appears after the first space it encounters - including
the space itself. The result would be if I printed $name, only John or Jane
would be shown, the last name was removed. Hope I have explained this ok.
Thanx to all who read or respond. Code examples are greatly appriciated.

R




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

Date: Sun, 27 Jul 2003 02:04:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Need help chopping data in Perl
Message-Id: <bfv4ve$j494g$1@ID-184292.news.uni-berlin.de>

"Dandy" Randy wrote:
> I'm needing a set of commands that will take the variable $name ...
> and remove any data that appears after the first space it
> encounters - including the space itself.

     $name =~ s/^(\S+).*/$1/;

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



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

Date: Sun, 27 Jul 2003 00:58:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Need help chopping data in Perl
Message-Id: <CsFUa.3803$FP5.1441@nwrddc02.gnilink.net>

"Dandy" Randy wrote:
> Jogn Doe|john(@)email.com
> Jane Doe|jane(@)email.com
>
> The sending script opens this file and assigns its data to a @ array.
[...]
> How can I chop
> off the last name from the name data? The first name and last name
> are separated by a simple space.

You want to use split(), details please see 'perldoc -f split'

jue




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

Date: Sat, 26 Jul 2003 22:24:20 +0200
From: Fred Flintstone <>
Subject: Newbie Question
Message-Id: <fuc5ivkrpa1rtn2d8u5kf8oe325ajnladq@4ax.com>

Hey. Im new to programming and need some basic Perl help.

my($var1,$var2) = @_;
I understand that the "my" defines the two variables as private to the
enclosing block of code. I dont understand the "@_". My book says its
a special local array. Its been used in the following:

## Beginning of login.pl
%usermap = qw(
	new		password
);

print "Enter name: ";
$name = <STDIN>;
chomp ($name);

print "Enter password: ";
$gpasswd = <STDIN>;
chomp ($gpasswd);

if (auth_check($name,$gpasswd)) {
	print "Correct\n";
}
else {
	print "Incorrect\n";
}

sub auth_check {
	my ($prvname,$prvgpasswd) = @_;
	if ($usermap{$prvname} eq $prvgpasswd) {
		return 1;
	}
	else {
		return 0;
	}
}
## EOF

Could someone please explain this speical local array to me in more
detail.
Thank you in advance for your help.
--FF


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

Date: Sat, 26 Jul 2003 22:34:19 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie Question
Message-Id: <bfuol2$iijrm$1@ID-184292.news.uni-berlin.de>

Fred Flintstone wrote:
> I dont understand the "@_". My book says its a special local array.

It contains a list of the arguments that were passed to a subroutine.

> Could someone please explain this speical local array to me in more
> detail.

perlsub explains it best: 
http://www.perldoc.com/perl5.8.0/pod/perlsub.html

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



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

Date: Sat, 26 Jul 2003 11:56:46 -0700
From: Eric <nospam@xx.com>
Subject: Re: Pesky added line
Message-Id: <3F22CEEE.7C639420@xx.com>

John W. Krahn was kind enough to point out:

>>       print OUTFILE "$line\n";
>
>This is your problem.  You don't remove the original newline and add
>another one here.
>
>      print OUTFILE $line;

Tnx, John.  I thought about that but it didn't make any sense to me that
the blank line would come before the substitution line!


Thomas Wasell further enhanced my Perl learning experience:

> >
> >...i.e, the word "Active" gets replaced with "1" ...
> 
> Not on my machine! It adds a newline after _every_ line. (Your not
> chomp()ing $line AND adding a newline when you print.)

Yikes!

> >#!/usr/bin/perl -w
>                  ^^
> You have 'use warnings;' below, so this is not necessary.

Ooops...tnx.

> >my $infile = " ";
> >my $outfile = " ";
> >my $line = " ";
> 
> Why are you initialising these variables to blank space?

I cloned this from another script I had which would NOT work if I just
used "" without a space.

> >      $line =~ s/"Active\"/\"1\"/g unless $line !~ m/\"Active\"/;
>                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> This is _completely_ useless AND has a confusing double negation! There's no need to escape the double-quotes.

Umh, I've been used to escaping double-quotes in .php lately ;-(

> The while-loop is better written:
> 
>     while (<INFILE>) {
>         s/"Active"/"1"/g;
>         s/"Pending Release"/"2"/g;
>         #  etc...
>         print OUTFILE;
>     }

WOW!  Tnx again for helping bring me out of the dark ages. Posting to
this newsgroup always ends up being a great educational (and humbling)
experience :-)

Regards to both of you,

Eric


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

Date: Sat, 26 Jul 2003 15:07:11 -0600
From: Ryan Thompson <a@ry.ca>
Subject: Re: Simple site index
Message-Id: <20030726145758.A25949-100000@ren.sasknow.com>

reggie wrote to :

> I am looking for help on choosing Perl modules for the following task:
>
> Create an index of all html files on a site
>   file - <title>

Easy with a regexp. Even easier if you're already using
HTML::(Pull)?Parser for more complex tasks.

> where 'file' is the directory+filename and '<title>' is the text
> between the opening and closing HTML title tags.
>
> I do not have access to the files system so I must go through HTTP.
>
> I've rolled my own in the past, but this is for a client and I
> wouldn't mind being pointed towards any modules that will help me best
> ensure the task is thurough and complete.
>
> I am looking at LWP::Simple, HTML::Parser, HTML::SimpleLinkExtor

LWP::Simple will definitely be helpful. HTML::Parser (or even
HTML::PullParser) will work wonders, especially for pulling out links.

That being said, you definitely wouldn't be the first to write a web
spider. :-) Consider existing applications that may already fit this
purpose.

> but I am concerned at my own 'local link' routines (to ensure my code
> follows <all but only> local links).  Any suggestions there?

That's an awkward statement. I'm assuming you mean "Ensure my code only
follows local links". Look into URI::URL; in particular, something like:

    use URI::URL;
    my $url = 'http://www.website.com/cgi-bin/some-script.pl?param=arg';
    my $host = url($url)->host;

Which will give you the host portion of the url $url. Check that to
ensure you're confining your requests to the same host, possibly with
some minor mangling if you want to catch one of several equivalent
hosts.

Hope this helps,
- Ryan

-- 
  Ryan Thompson <ryan@sasknow.com>

  SaskNow Technologies - http://www.sasknow.com
  901-1st Avenue North - Saskatoon, SK - S7K 1Y4

        Tel: 306-664-3600   Fax: 306-244-7037   Saskatoon
  Toll-Free: 877-727-5669     (877-SASKNOW)     North America



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

Date: 26 Jul 2003 13:50:37 -0700
From: mjeff1@twcny.rr.com (Jeff Mott)
Subject: Re: Tracking Number
Message-Id: <970676ed.0307261250.3d0f27b1@posting.google.com>

> You know, you can search cpan

I know. You even quoted my statement that I had already searched CPAN
and not found what I was looking for. Why did you assume I had not?
Did you just quote me without actually reading what I had said?


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

Date: 26 Jul 2003 14:57:02 -0700
From: dwlepage@yahoo.com (david)
Subject: use File::Archive extracting zip's with '.' in front of name
Message-Id: <b09a22ae.0307261357.1812f9d@posting.google.com>

I have a script to extract any ZIP files in the current directory. The
problem is when they are extracted, the program puts a . in front of
the file names.

#!/usr/bin/perl -w

use strict;
use Archive::Zip qw(:ERROR_CODES);

opendir(DIR, ".") || die "Can't open local directory : $!";
my @zips = grep { -f "./$_" } readdir (DIR);
close(DIR);
foreach my $zipfiles (@zips) {
        if ($zipfiles =~ /\w+\.zip$/) {
                my $zip = Archive::Zip->new();
                my $zipName = "$zipfiles";
                my $status = $zip->read( $zipName);
                die "Read of $zipName failed\n" if $status != AZ_OK;
                        print "$zipfiles\n";
                $zip->extractTree();
                #unlink($zipfiles);                
        }

}

If I have a file called a.zip with a file in it called 'a', the script
will extract it as '.a'

How can I get around this?

Thanks,


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

Date: Sat, 26 Jul 2003 16:50:58 +0100
From: "Julian Scarfe" <julian@avbrief.com>
Subject: Re: XML or home-grown format?
Message-Id: <yrxUa.2367$G85.1916@newsfep4-winn.server.ntli.net>

"JS Bangs" <jaspax@u.washington.edu> wrote in message
news:Pine.A41.4.56.0307241439550.111292@dante03.u.washington.edu...

> For example, I can currently write the following line in a file to be
> parsed by Lingua::Phonology::Symbols:
>
> d    +anterior -distributed voice
>
> In XML, this might have to be as verbose as:
>
> <symbol label="d`">
>     <feature name="anterior" value="+" \>
>     <feature name="distributed" value="-" \>
>     <feature name="voice" \>
> </symbol>
>
> Which is significantly heavier and less clear. I'm rather torn on this, so
> I was wondering what insight the minds here have to offer. Many thanks--

My guess is that you find this less clear because you're used to reading the
current format.  However:

<symbol label="d">
    <feature name="anterior" value="true" \>
    <feature name="distributed" value="false" \>
    <feature name="voice" \>
</symbol>

means a great deal more to me than trying to work out what your +s and -s
mean.  The structure is immediately clear and it's not hard to edit using an
XML editor or even a simple text editor. I'd check out XML schema (rather
than playing with DTDs)  if you haven't already.

Julian Scarfe





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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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