Help - Search - Member List - Calendar
Full Version: combinations
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44
Support our Sponsors!
In a message dated 6/18/2004 3:37:17 AM Eastern Standard Time,
[Email Removed] writes:
QUOTE
- is it possible to search an array for a certain element, and that the
search returns the element index? eg. searching for 156 in the array
(123, 456, 156, 1354, 35164, 654656, 654, 846) should give 2
Look into List::Util (first() function)


-will
http://www.wgunther.tk
(the above message is double rot13 encoded for security reasons)

Most Useful Perl Modules
-strict
-warnings
-Devel::DProf
-Benchmark
-B::Deparse
-Data::Dumper
-Clone
-Perl::Tidy
-Beautifier
-DBD::SQLite

Jorge Goncalves
Hi, I have a text file like this:

1 Chaque L Ma Me J V S D 00:20
D:muselotusnotesextractStat.exe StatA090 j
2 Chaque L Ma Me J V S D 00:21
D:muselotusnotesextractStat.exe StatA090 m
3 Chaque L Ma Me J V S D 00:22
D:muselotusnotesextractStat.exe StatA090 h
4 Chaque L Ma Me J V S D 00:23
D:muselotusnotesextractStat.exe StatB090 j
5 Chaque L Ma Me J V S D 00:27
D:muselotusnotesextractStat.exe StatPMF090 m
6 Chaque L Ma Me J V S D 00:28
D:muselotusnotesextractStat.exe StatPMF090 h
7 Aujourd'hui 20:00
D:muse3test.exe
8 Chaque L Ma Me J V S D 00:28
D:muselotusnotesextractStat.exe StatPMF090 h

How can i do in Perl to get the first number if the last part of the
line doesn't contains extractStat.
for exemple here to get only the number 7.

Thanks

Chris Charley
----- Original Message -----
From: "Jorge Goncalves" <[Email Removed]>
Newsgroups: perl.beginners
To: <[Email Removed]>
Sent: Friday, June 18, 2004 4:35 AM
Subject: Re:seach a number in a file


QUOTE
Hi, I have a text file like this:

[snip file contents, they're posted below]

QUOTE
How can i do in Perl to get the first number if the last part of the
line doesn't contains extractStat.
for exemple here to get only the number 7.

Thanks

Hello Jorge,
This code will do what you want. You may also want to check:

For the 'm' modifier
perldoc perlretut (see using character classes)
perldoc perlre

Could not find docs for the 'g' modifier. Maybe someone else could point
out where it is best explained.

Chris

#!/usr/bin/perl
use strict;
use warnings;

{
local $/; # undefine input record separator - read in whole file as
1 line ($file).
my $file = <DATA>;
# m modifier allows ^ to match immediately after a newline, and $ to
match preceding a newline
# g modifier is for a progressive match - start next match immediately
after end of previous one
while ($file =~ /^s+(d+).+n(.+)$/mg) {
print $1 unless $2 =~ /extractStat/;
}
}

__DATA__
1 Chaque L Ma Me J V S D 00:20
D:muselotusnotesextractStat.exe StatA090 j
2 Chaque L Ma Me J V S D 00:21
D:muselotusnotesextractStat.exe StatA090 m
3 Chaque L Ma Me J V S D 00:22
D:muselotusnotesextractStat.exe StatA090 h
4 Chaque L Ma Me J V S D 00:23
D:muselotusnotesextractStat.exe StatB090 j
5 Chaque L Ma Me J V S D 00:27
D:muselotusnotesextractStat.exe StatPMF090 m
6 Chaque L Ma Me J V S D 00:28
D:muselotusnotesextractStat.exe StatPMF090 h
7 Aujourd'hui 20:00
D:muse3test.exe
8 Chaque L Ma Me J V S D 00:28
D:muselotusnotesextractStat.exe StatPMF090 h

Mandar Rahurkar
Hi All,
what wud be the regexp for :

1. substituting last s of every word
e.g., forests become forest, goats becomes goat

2. removing all one and two lettered words
e.g., a,an

Thanks,
Mandar

Gunnar Hjalmarsson
Tim Johnson wrote:
QUOTE
Gunnar Hjalmarsson wrote:
Tim Johnson wrote:
Chetak Sasalu wrote:

<regex suggestion snipped>

QUOTE
That is one way to do it, but maybe you should tell him what it
is that the regex does.  I remember from my newbie days that
it wasn't too useful when people just threw regexes at me
without explaining them because they look so daunting before
you are used to them.

Chetak *could* have done so, but doing it is certainly nothing
you can claim that he *should* do. What *should* happen is that
the OP ("Jack Jack") start studying some appropriate
documentation, ...

I didn't say that Chetak's reply was wrong, or that he was somehow
remiss in omitting that information.

I did understand your response as if you implied the latter. My
apologies if I was wrong.

QUOTE
But here's where we differ:  Regular expressions are quite possibly
one the hardest part of learning effetive Perl programming,and
arguably the most valuable.  Handing someone a finished regular
expression without explaining how it works doesn't really help
someone learn how to make their own regular expressions.

I would say that nobody can learn regular expressions without serious
own efforts. To somebody who is seriously trying to learn, I believe
that a finished regex *can* be helpful in the learning process, since
it serves the purpose of pointing the questioner in the right
direction. Personally I learned regexes basically by studying finished
Perl programs while using the docs to figure out what was happening.

When helping somebody understand regexes, it's often pretty easy to
simply show how a problem can be solved. Adding comments that explain
every single detail is harder and much more time-consuming. If
somebody wants to do it, it's excellent, but the point I was trying to
make is that you can't expect that. The natural way IMO is that the
questioner seeks the explanations in the docs. (A pointer to relevant
docs is always a good idea, though.)

QUOTE
You maintained that if he really enjoyed the fish he was given and
wanted another one bad enough, he would have gone out and found a
book on fish and from there derived that fishing would have been
the approprate way to get a fish, studied up on it and come back
when he had problems fishing

Yes, I did. I was assuming that one single fish will only still his
hunger temporarily, and that he realises that he needs to learn how to
fish. ;-)

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

Jorge Goncalves
Hi List , I have this to print:
1
2
3

with this script but it didn't work:
#!/usr/bin/perl
use strict;
use warnings;

{
local $/;
my $file = <DATA>;
while ($file =~ /^s+(d+).(.+)$/) {
print $1n if $2 =~ /extractStat/;
}
}

__DATA__
?tat ID Jour Heure Ligne de
commande
-------------------------------------------------------------------------------

1 Chaque L Ma Me J V S D 00:20
D:lotusnotesextractStat.exe StatA090 j
10 Demain 10:00 testtest2
2 Chaque L Ma Me J V S D 00:21
D:lotusnotesextractStat.exe StatA090 m
25 Tomorow onlytesting
3 Chaque L Ma Me J V S D 00:22
D:lotusnotesextractStat.exe StatA090 h

Gunnar Hjalmarsson
Jorge Goncalves wrote:
QUOTE
Hi List , I have this to print:
1
2
3

with this script but it didn't work:

No, it does not even compile. :(

QUOTE
while ($file =~ /^s+(d+).(.+)$/) {

You always need the /g modifier when using the m// operator that way
in a while loop. In this case you also need the /m modifier. Check out

perldoc perlop

about what those modifiers are doing.

while ($file =~ /^s+(d+).(.+)$/gm) {

QUOTE
print $1n if $2 =~ /extractStat/;

Let's first correct the compilation error (something you should have
done before posting, btw).

print "$1n" if $2 =~ /extractStat/;

But now the script just outputs "uninitialized" warnings.

It's time to consider the program logic. $1, $2 etc. contain what was
captured in the last successful match. This would make the program
logic appear more clearly:

if ($2 =~ /extractStat/) {
print "$1n";
}

The point with that is to show that when the program comes to print
"$1n", the last successful match is no longer the m// operator in the
while loop, but it's $2 =~ /extractStat/. Since nothing was captured
there, $1 is undefined, which explains the warning messages.

This is one way to deal with it:

my $tmp = $1;
print "$tmpn" if $2 =~ /extractStat/;

HTH

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

Tim Johnson
Check out the Win32::TieRegistry module. It's pretty easy to get that
info from the Registry.

-----Original Message-----
From: [Email Removed] [mailto:[Email Removed]]
Sent: Tuesday, June 22, 2004 11:32 AM
To: [Email Removed]
Subject: [Doubt]: Retrieve System Info like Which OS and type

Hi,


I need to retrieve the following system Info from the current system.

1. Operating System

2. Localization

3. 32 Bit or 64 Bit

Akshatha Hande
? Used for pattern matching where in it matches exactly one character after
the pattern that you have provided.

Similarly * will match zero or more characters.

-----Original Message-----
From: LKTee [mailto:[Email Removed]]
Sent: Thursday, June 24, 2004 9:13 AM
To: '[Email Removed]'
Subject: String File


Dear All,



I try command below in Unix



$ ls -l file?

-rw-r-r-- 1 root 125 May 27
11:11 file1

-rwxr-x- 1 root 52125 May 27 19:11
file2

drwxr-xr-x 1 root 442 May 27 20:11
file3





May I know that the purpose of the "?" in the string file?

Mandar Rahurkar
Hi All,
I need to searh through a text file and lookfor a keyword and print
the immediate word following it and before it. for eg.,

$_="bird was eating fish";

output for keyword eating shd be: was eating fish

this is what i am doing,

$key="dog";
@sspace=`cat file.txt`;

foreach(@sspace) {
/ (.*) $key w/;
print "$1";
print "$2n";
}

this doesnt work and prints the entire line...how do i get it to wordwise
?

thanks
Mandar

Wiggins D Anconia
QUOTE
I am using following code to validate e-mail addresses

if ($mail =~ m/^(w+(.|-))*w+@(w+(.|-)*)+w+$/){
valid
}else{
invalid
}

it will give valid results for all of the following e-mail address

[Email Removed]
[Email Removed]
[Email Removed]
[Email Removed]


...

but I am not sure about the illegal chars for an e-mail address
can someone check above code tell me whether this matches all the valid
e-maill
address and only the valid e-mail addresses.


Use the Email::Valid module from CPAN. If you are curious about how
complex an email address can truly get check out the source for the
module. I believe it is mostly taken from the regex provided in the
appendix of the Mastering Regular Expressions O'Reilly book. It will
truly blow your mind...

http://danconia.org

from what I remember reading and was told as a best practice using exec
/.../..../ was recommended over system. For this reason exec does not
create a child and therefore does not have to wait. the perl process
itself runs the command or program. what are the pros and cons of each?

thanks


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






u235sentinel <[Email Removed]>
06/25/2004 11:58 AM


To:
cc: [Email Removed]
Subject: Re: 'system' and parallel execution (was: Re: How to call a perl
script....)




Wiggins d Anconia wrote:

QUOTE

Not exactly, it has been forked and does technically run in parallel,
however 'system' blocks your current process waiting for the child to
finish, so your process is in fact running, but it won't be doing any
work except for waiting for a signal from the child.

There are other ways to have parallel execution,

perldoc perlipc
perldoc -f fork
perldoc -f system

Ok.  I'll read those in a minute.  After reviewing Learning Perl, I

realize I need to open the process as a file handle for parallel
operations. Called a "piped open". (page 201 Oreilly Learning Perl).

QUOTE
Will get you started. "Network Programming with Perl" by Lincoln Stein
also has excellent chapters on this subject, though lacks a chapter
(probably because of its age) on POE.


Haven't purchased that book yet (it's on my amazon wish list however).

I'll check it out.

Thanks!

U235sentinel
Exec will shell out and run whatever exec called. At least I believe
the correct term is "shell out". Learning Perl says in page 196 that
exec locates the program you called and jumps to it. There is no perl
process anymore. So I guess it's more of an exit Perl and run this
command sort of thing.. So once you do that, Perl is gone. System
however returns you back to Perl. If you want Perl not to wait you can
open a process as a file handle. I haven't tried it however it suggests
this will run Perl and your process in parallel.

Something to try



[Email Removed] wrote:

QUOTE
from what I remember reading and was told as a best practice using exec
/.../..../ was recommended over system.  For this reason exec does not
create a child and therefore does not have to wait.  the perl process
itself runs the command or program.  what are the pros and cons of each?

thanks


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






u235sentinel <[Email Removed]
06/25/2004 11:58 AM


To:
cc:    [Email Removed]
Subject:        Re: 'system' and parallel execution (was: Re: How to call a perl
script....)




Wiggins d Anconia wrote:



Not exactly, it has been forked and does technically run in parallel,
however 'system' blocks your current process waiting for the child to
finish, so your process is in fact running, but it won't be doing any
work except for waiting for a signal from the child.

There are other ways to have parallel execution,

perldoc perlipc
perldoc -f fork
perldoc -f system



Ok.  I'll read those in a minute.  After reviewing Learning Perl, I
realize I need to open the process as a file handle for parallel
operations.  Called a "piped open". (page 201 Oreilly Learning Perl).



Will get you started. "Network Programming with Perl" by Lincoln Stein
also has excellent chapters on this subject, though lacks a chapter
(probably because of its age) on POE.




Haven't purchased that book yet (it's on my amazon wish list however).
I'll check it out.

Thanks!






Wiggins D Anconia
QUOTE

Exec will shell out and run whatever exec called.  At least I believe
the correct term is "shell out".  Learning Perl says in page 196 that
exec  locates the program you called and jumps to it.  There is no perl
process anymore.  So I guess it's more of an exit Perl and run this
command sort of thing..

Correct.

perldoc -f exec

For more.

So once you do that, Perl is gone. System
QUOTE
however returns you back to Perl.  If you want Perl not to wait you can
open a process as a file handle.  I haven't tried it however it suggests
this will run Perl and your process in parallel.


Yes, alternatively you can use fork+exec to have a forked process that
is non-blocking, the reason to use pipes is so that the two can
communicate more easily, this isn't always desired.

QUOTE

Something to try


perldoc perlipc
perldoc perlfork
perldoc IPC::Open3

Explains most of this, much better than I can.

http://danconia.org

QUOTE


[Email Removed] wrote:

from what I remember reading and was told as a best practice using exec
/.../..../ was recommended over system.  For this reason exec does not
create a child and therefore does not have to wait.  the perl process
itself runs the command or program.  what are the pros and cons of each?

thanks


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






u235sentinel <[Email Removed]
06/25/2004 11:58 AM


To:
cc:    [Email Removed]
Subject:        Re: 'system' and parallel execution (was: Re:
How to call a perl
script....)




Wiggins d Anconia wrote:



Not exactly, it has been forked and does technically run in parallel,
however 'system' blocks your current process waiting for the child to
finish, so your process is in fact running, but it won't be doing any
work except for waiting for a signal from the child.

There are other ways to have parallel execution,

perldoc perlipc
perldoc -f fork
perldoc -f system



Ok.  I'll read those in a minute.  After reviewing Learning Perl, I
realize I need to open the process as a file handle for parallel
operations.  Called a "piped open". (page 201 Oreilly Learning Perl).



Will get you started. "Network Programming with Perl" by Lincoln Stein
also has excellent chapters on this subject, though lacks a chapter
(probably because of its age) on POE.




Haven't purchased that book yet (it's on my amazon wish list however).
I'll check it out.

Thanks!








ok then I think system is more ideal for most situations.

thanks,

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






"Wiggins d Anconia" <[Email Removed]>
06/25/2004 12:40 PM


To: u235sentinel <[Email Removed]>, [Email Removed]
cc:
Subject: Re: 'system' and parallel execution (was: Re: How to call a perl
script....)


QUOTE

Exec will shell out and run whatever exec called.  At least I believe
the correct term is "shell out".  Learning Perl says in page 196 that
exec  locates the program you called and jumps to it.  There is no perl
process anymore.  So I guess it's more of an exit Perl and run this
command sort of thing..

Correct.

perldoc -f exec

For more.

So once you do that, Perl is gone. System
QUOTE
however returns you back to Perl.  If you want Perl not to wait you can
open a process as a file handle.  I haven't tried it however it suggests

this will run Perl and your process in parallel.


Yes, alternatively you can use fork+exec to have a forked process that
is non-blocking, the reason to use pipes is so that the two can
communicate more easily, this isn't always desired.

QUOTE

Something to try


perldoc perlipc
perldoc perlfork
perldoc IPC::Open3

Explains most of this, much better than I can.

http://danconia.org

QUOTE


[Email Removed] wrote:

from what I remember reading and was told as a best practice using exec

/.../..../ was recommended over system.  For this reason exec does not
create a child and therefore does not have to wait.  the perl process
itself runs the command or program.  what are the pros and cons of
each?

thanks


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams






u235sentinel <[Email Removed]
06/25/2004 11:58 AM


To:
cc:    [Email Removed]
Subject:        Re: 'system' and parallel execution (was: Re:
How to call a perl
script....)




Wiggins d Anconia wrote:



Not exactly, it has been forked and does technically run in parallel,
however 'system' blocks your current process waiting for the child to
finish, so your process is in fact running, but it won't be doing any
work except for waiting for a signal from the child.

There are other ways to have parallel execution,

perldoc perlipc
perldoc -f fork
perldoc -f system



Ok.  I'll read those in a minute.  After reviewing Learning Perl, I
realize I need to open the process as a file handle for parallel
operations.  Called a "piped open". (page 201 Oreilly Learning Perl).



Will get you started. "Network Programming with Perl" by Lincoln Stein
also has excellent chapters on this subject, though lacks a chapter
(probably because of its age) on POE.




Haven't purchased that book yet (it's on my amazon wish list however).
I'll check it out.

Thanks!










--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Randal L. Schwartz
QUOTE
"DBSMITH" == DBSMITH  <[Email Removed]> writes:

DBSMITH> from what I remember reading and was told as a best practice using exec
DBSMITH> /.../..../ was recommended over system. For this reason exec does not
DBSMITH> create a child and therefore does not have to wait. the perl process
DBSMITH> itself runs the command or program. what are the pros and cons of each?

Well, the difference is whether a goto or a subroutine call will work
for you.

system() creates a kid, makes the kid do the work. Then you get
to resume doing what you are doing.

exec() sends you to do the work, and there's no returning.

Each has its place and purpose.

If the *very last* thing you're doing is system(), you can probably
replace that with exec(), and it'd be better. But otherwise, they
are clearly not interchangable.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

U235sentinel
Wiggins d Anconia wrote:

QUOTE
perldoc -f exec

Ok.  makes sense.


*** Since it's a common mistake to use "exec" instead
of "system", Perl warns you if there is a following
statement which isn't "die", "warn", or "exit" ***

I've pretty much decided it's either system or a filehande process for
me. I don't see myself using exec too often :-)

QUOTE
Yes, alternatively you can use fork+exec to have a forked process that
is non-blocking, the reason to use pipes is so that the two can
communicate more easily, this isn't always desired.



I get the impression that fork may not be a good idea. Perldoc suggests
it "could" leave zombie child processes hanging around. It also gives a
suggestion how to fix this ($SIG(CHLD)). Not sure this really is a
great idea. It would affect not just Perl but other system processes
running. Might not want to set it to ignore. Also, it makes the
presumption the system has that handy.

The thing I really like about Perl, there is always another way to do
something :-)

This exercise has really helped my understanding BTW. I appreciate the
help!!!

Wiggins D Anconia
QUOTE

ok then I think system is more ideal for most situations.


It's dangerous to make blanket statements like this. Each is a tool that
should be understood and applied in the right manner. That is why it is
more important to understand the concepts of process execution,
parallelism, blocking, etc. rather than any one particular function.
'system' is really just a combination of a fork+exec+waitpid model that
is easy to use, the backticks are similar to the open pipe model, but
generally easier to use as well, the open pipe model is really just a
fancy version of the same fork+exec+waitpid model. So some would claim
you should use fork+exec+waitpid, because 'system' really just uses
them, others would say that is the beauty of Perl, 'system' provides a
very good shortcut, assuming it accomplishes the goal.

Bottom line is that it is really the situation that will dictate which
is "best". And "more ideal for most situations" really becomes a
function of the type of job you are in, the type of code you usually
find yourself working on, and what you consider to be "production" level
of quality.

Just a couple of cents,

http://danconia.org

U235sentinel
Wiggins d Anconia wrote:

QUOTE
It's dangerous to make blanket statements like this. Each is a tool that
should be understood and applied in the right manner.

I agree with this.  Generally system would be the right fit for many of

my Perl programs. However exec has it's place like any tool.

QUOTE
That is why it is
more important to understand the concepts of process execution,
parallelism, blocking, etc. rather than any one particular function.
'system' is really just a combination of a fork+exec+waitpid model that
is easy to use, the backticks are similar to the open pipe model, but
generally easier to use as well, the open pipe model is really just a
fancy version of the same fork+exec+waitpid model.  So some would claim
you should use fork+exec+waitpid, because 'system' really just uses
them, others would say that is the beauty of Perl, 'system' provides a
very good shortcut, assuming it accomplishes the goal.

hmm... So system could generate zombie processes?  Or a filehandle

process?

I guess it really depends on what we are kicking off and whether it
exists cleanly.

Wiggins D Anconia
QUOTE

Wiggins d Anconia wrote:

It's dangerous to make blanket statements like this. Each is a tool that
should be understood and applied in the right manner.

I agree with this.  Generally system would be the right fit for many of
my Perl programs.  However exec has it's place like any tool.

That is why it is
more important to understand the concepts of process execution,
parallelism, blocking, etc. rather than any one particular function.
'system' is really just a combination of a fork+exec+waitpid model that
is easy to use, the backticks are similar to the open pipe model, but
generally easier to use as well, the open pipe model is really just a
fancy version of the same fork+exec+waitpid model.  So some would claim
you should use fork+exec+waitpid, because 'system' really just uses
them, others would say that is the beauty of Perl, 'system' provides a
very good shortcut, assuming it accomplishes the goal.

hmm... So system could generate zombie processes?  Or a filehandle
process?

I guess it really depends on what we are kicking off and whether it
exists cleanly.



Theoretically any process that starts a subprocess can result in the
creation of zombies. 'system' *should* be protected from this (read: I
don't really know because I am definitely not an internals expert)
because of either how waitpid is written or because it can temporarily
adjust the CHLD sig handler. I am unclear about exactly how this stuff
works, again not an internals person.

Essentially you are correct, though the important part is how the parent
exits, not the child. zombies are created when the parent exits before
all of its children (at least those that are not auto reaped),
essentially no process is then 'waiting' for them. I suspect the
thinking is that if you know enough of how to create sub processes, then
you should know enough of how to deal with them correctly, aka reading
exit codes, doing IPC, waiting for them to clean up, etc. Not having to
know all of this yourself, is why 'system', backticks, piped opens, and
POE are so nice.

Just for the archives, I have never had a problem of zombies being left
over by a program calling either 'system' or a piped open. (The problem
only seems to present itself when I write my own forking code ;-)).

http://danconia.org

Wiggins D Anconia
QUOTE

I'm in a situation wherein I want to brush up on my 'Perl', but have
no personal computer. I'm currently reading my way through "Learning

Pearl", but can't do the exercises because I only have access to
'Windows' machines that do not have Perl installed at all. Is there a
way to use Perl on-line from such a machine? Is Perl small enough to be
installed on a floppy disk that can be moved from machine to machine?
QUOTE

Is it possible to use 'Perl' without having to install it on a
particular machine?


As the others have pointed out, you can install Perl on windows. You
*might* be able to get it to run from a CD provided the drive letter was
the same (but this is very theoretical, and might prove difficult). If
you are at school there is bound to be a unix box of some sort around
that will have it installed, ask around and see if you can get an
account to play with Perl. If not at school, you could certainly get a
cheap hosting account at an online hoster, pick one with shell access,
and practice up your Perl that way, of course that would be more
expensive than just buying a computer these days eventually. You could
probably get a computer on Ebay for less than $200 and install Linux to
avoid the M$ tax.....

You might also visit a local Perl Mongers group and ask one of the
members if you could have access to their machine, one of them is bound
to have a server accessible from the internet and would consider giving
another member an account provided you didn't abuse it.

http://danconia.org

Remo Sanges
On Jun 25, 2004, at 8:50 PM, Wiggins d Anconia wrote:

QUOTE

I'm in a situation wherein I want to brush up on my 'Perl', but have
no personal computer. I'm currently reading my way through "Learning
Pearl", but can't do the exercises because I only have access to
'Windows' machines that do not have Perl installed at all. Is there a
way to use Perl on-line from such a machine? Is Perl small enough to be
installed on a floppy disk that can be moved from machine to machine?

Is it possible to use 'Perl' without having to install it on a
particular machine?


As the others have pointed out, you can install Perl on windows. You
*might* be able to get it to run from a CD provided the drive letter
was
the same (but this is very theoretical, and might prove difficult).  If
you are at school there is bound to be a unix box of some sort around
that will have it installed, ask around and see if you can get an
account to play with Perl.  If not at school, you could certainly get a
cheap hosting account at an online hoster, pick one with shell access,
and practice up your Perl that way, of course that would be more
expensive than just buying a computer these days eventually. You could
probably get a computer on Ebay for less than $200 and install Linux to
avoid the M$ tax.....

You might also visit a local Perl Mongers group and ask one of the
members if you could have access to their machine, one of them is bound
to have a server accessible from the internet and would consider giving
another member an account provided you didn't abuse it.

....or finally you can try with a linux-live distribution like knoppix:
http://www.knoppix.org/
It comes with perl like every linux... and a lot of other stuff and...
no configuration problems.
You don't need to install anithing, you need only the 'permissions' to
reboot the computer from cd and play with it until the end of the day!

Remo

Bob Showalter
Ron Smith wrote:
QUOTE
... I only have access to
'Windows' machines that do not have Perl installed at all.
Is there a way to use Perl on-line from such a machine?

Go to http://www.activestate.com/Products/ActivePerl/ and install ActivePerl
(free).

QUOTE
Is Perl small enough to
be installed on a floppy disk that can be moved from machine to
machine?

Nope. It may have at one time.
http://www.perldoc.com/perl5.8.0/pod/perlhist.html

The ActiveState .msi installation image _will_ fit on a CD.

QUOTE

Is it possible to use 'Perl' without having to install it on a
particular machine?

Not really. There are various ways of "bundling" an application for
deployment on a target machine without having to install Perl separately.
You can also install Perl on a network share and run it that way I guess.

Rod Za
Bob and Thomas,

Thank you, very much.

Rod Za

--- Bob Showalter <[Email Removed]> wrote:
QUOTE
Rod Za wrote:
Hi all,

i'm trying to make a code that get a file name (with full path) and
change the first char of the filename. Someone can say me if there's
a better way to do this?:

_BEGIN_
#!/usr/bin/perl -w

use strict;

my($file) = $ARGV[0];                #receives the filename

my $file = shift;    (the traditional idiom)

my @tmp = split(///,$file);          #split the path

use File::Basename;
my ($name, $path) = fileparse($file);  (more portable)

$tmp[$#tmp] =~ s/.(w+)/c$1/g;        #change the first char of the
filename

substr($name, 0, 1) = 'c';  (no need for regex)

my $IPPFile = join('/',@tmp);        #join again path+'/'+filename
print "Original Filename: $file - Changed Filename: $IPPFilen";
#print the result _END_

use File::Spec
print "Original name: ", $file,
" Changed name: ", File::Spec->catfile($path, $name), "n";

You might also have a look at the ubiquitous (and ancient) perl "rename"
script: http://www.cpan.org/scripts/nutshell/ch6/rename





__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

Bob Showalter
Rod Za wrote:
QUOTE
Hi all,

i'm trying to make a code that get a file name (with full path) and
change the first char of the filename. Someone can say me if there's
a better way to do this?:

_BEGIN_
#!/usr/bin/perl -w

use strict;

QUOTE
my($file) = $ARGV[0];                #receives the filename

my $file = shift; (the traditional idiom)

QUOTE
my @tmp = split(///,$file);          #split the path

use File::Basename;
my ($name, $path) = fileparse($file); (more portable)

QUOTE
$tmp[$#tmp] =~ s/.(w+)/c$1/g;        #change the first char of the
filename

substr($name, 0, 1) = 'c'; (no need for regex)

QUOTE
my $IPPFile = join('/',@tmp);        #join again path+'/'+filename
print "Original Filename: $file - Changed Filename: $IPPFilen";
#print the result _END_

use File::Spec
print "Original name: ", $file,
" Changed name: ", File::Spec->catfile($path, $name), "n";

You might also have a look at the ubiquitous (and ancient) perl "rename"
script: http://www.cpan.org/scripts/nutshell/ch6/rename

Bob Showalter
WEBMASTER wrote:
QUOTE
Hello everybody.

Hi. Real names appreciated.

QUOTE

I am on a new server and have discovered the Directories in the
CGI-BIN are visible to everybody. This is, if a type
www.mysite.com/cgi-bin  I get a list of all the files and
subdirectories, and so for every subdirectory.

I had never had this issue.

Somebody has mucked with the server configuration.

QUOTE

What is the best permission for my directories?

Not the issue.

QUOTE

Now, they are 755, but I'm not sure if changing it will cause the
scripts not to run.

That should be fine.

QUOTE

The other way would be to place an index.html file in every directory
causein the files not to get listed, but I'm sure there's a correct
way to do it.

You need to disable index generation. It's not a permission issue. It's also
not a Perl issue. Read the docs for your web server.

HTH

Wiggins D Anconia
Please bottom post, and group reply so that everyone can help and be
helped, and to prevent accidental ignoring of your post.

QUOTE

Hello wiggins,

Thanks,

My requirement is i have two arrays @element  and @size that i have
got by splitting.


Probably you should adjust the code at the 'split' time in anticipation
of your future needs, the need for two arrays that are then combined is
an indication of a design flaw. Post more code to have that looked over...

QUOTE
I want to map first element of @element with first element of @size
seperated with a colon . (in a loop how should i do it for all elements

in arrays),i want this output in an array @mapped.
QUOTE


for eg:
file1  : 1
file2  : 2
file3  : 3

so if say print @c

i should have output as follows

file1  : 1
file2  : 2
file3  : 3



I am assuming the arrays are the same size...

my @c;
foreach my $index (0 .. $#element) {
$c[$index] = "$element[$index] : $size[$index]";
}

works?

http://danconia.org

<snip old posts>

Wiggins D Anconia
QUOTE
Hi,
My perl script which uses CGI module fails to work
in Solaris giving Standard HTTP 500 Internal server
error.I checked the Apache log. It says  "Premature
end of script headers:"

But it works fine in HPUX and Windows. Is there any
thing That has to be take care of in Solaris.


Only that CGI be installed. Have you tried running the script from the
command line and checking its output? Are the Perl versions, and CGI.pm
versions identical? Generally the error you state is caused by either
failure to execute the script at all, or something being printed before
a proper header. If you try to run the script from the command line be
sure to do it as the user the web server runs as, and note that the
environment when logged in at a shell will be different than that of the
web server's environment.

QUOTE
Thanks in Advance.


See if you can provide more info,

http://danconia.org

Charlene Gentle
Hi

Thanx for all your help. With the time diffrence I only get the
reply's in the moring. Thanx a lot for the group's help.

Charlene




On Wed, 30 Jun 2004 08:12:00 +0200, [Email Removed] (Charlene
Gentle) wrote:

QUOTE
Thanx for the help Zentara.  Here are a part of my code.  I know that
I'm doning stuff the long way so if anyone could show me a shorter
way
it will be helpfull.  I wanted to put the sub's that I call into one
but
how?  The progress "meter"  have to show that it is still busy
scanning
the file, as soon as it is done and the file is closed, and the
output
have been given the meter should stop.  I don't want the user to
close
the program before the job is done.

Thanx

Hi

My program works thru long lists of word.  How can I show the user
that
it is still busy and when it is done.  Is there a progressmeter that
I
can insert into the while loop.  To have a perl/tk interface for the
user.

Hi...Ok I think I figured it out, without having any test files.
Below is the code.

What I did was go into your do_while sub and first count the total
lines by looping thru the filehandles, then I rewound the filehandles
to the beginning so they could be processed. Then as you process them,
I increment the progressbar by ( 100 / $linetotal ).

It seems to work, but I don't know what you are doing for sure.
In my testing, I create the test error file, then click each checkbox
and select a txt file. Then click the toets button.

Also I added a few select(undef,undef,undef,.01) statements
to slow down the files for testing. You can remove them for your
big files.


#!/usr/bin/perl
use Tk;
use IO::File;
use diagnostics;
use warnings;
use Tk::Balloon;

# added these lines
use Fcntl qw(:seek);
use Tk::ProgressBar;
my $linetotal = 0;
my $progressbar;
#

use vars qw(@c @bs @cb_value @i $sfile_val $newline @bt);
my $sfile = "";
my $file = "";
my $FILE0 = "";
my $FILE1 = "";
my $FILE2 = "";
my $FILE3 = "";
my $FILE4 = "";
my $FILE5 = "";
my $FILE6 = "";

# MAINWINDOW
my $main = new MainWindow();
drawInterface();
Tk::MainLoop();


# INTERFACE FOR USER <BUTTONS, CHECKBOX, ETC>
sub drawInterface {
$main->title("Check For Errors");
$main->configure( -background => 'gray' );
$main->geometry("300x300");

# MAAK FRAMES
my $opsFrm = $main->Frame( -background => 'gray' )->pack( -side =>
'top' );
my $keuseFrm = $main->Frame( -background => 'gray' );
my $opbtFrm =
$main->Frame( -background => 'gray' )->pack( -side => 'bottom'
);

# MAAK KEUSE VIR DIE SAVE LEER
$main->Label(
-text => "Create a file to save errors to",
-background => 'gray',
-font => "Helvetica -15 bold"
)->pack();
$main->configure( -background => 'gray' );
$main->Button(
-text => 'Create',
-width => 7,
-height => 1,
-command => sub { &do_save($main) }
)->pack( -pady => 3 );

# KEUSE BY TIPE LEERS
my $keuse = $keuseFrm->Label(
-text => "Maak 'n keuse",
-font => "Helvetica -15 bold"
)->pack( -side => 'top', -pady => 20 );
$keuse->configure( -background => 'gray' );
$keuseFrm->pack( -side => 'top', -fill => 'x' );

# CHECKBOX VIR LEERS WAT GEKIES WORD
$c[0] = $keuseFrm->Checkbutton(
-variable => $cb_value[0],
-offvalue => 0,
-onvalue => 1,
-text => "Dialects Upper",
-background => 'gray',
-command => sub {
if ( $cb_value[0] == 1 ) {
&do_get( $main, $c[0] = 0 );
}
}
)->pack( -side => 'top', -anchor => 'w', -padx => 20 );

$c[1] = $keuseFrm->Checkbutton(
-variable => $cb_value[1],
-offvalue => 0,
-onvalue => 1,
-text => "Dialects Lower",
-background => 'gray',
-command => sub {
if ( $cb_value[1] == 1 ) {
&do_get( $main, $c[1] = 1 );
}
}
)->pack( -side => 'top', -anchor => 'w', -padx => 20 );

$c[2] = $keuseFrm->Checkbutton(
-variable => $cb_value[2],
-offvalue => 0,
-onvalue => 1,
-text => "Coffensive Upper",
-background => 'gray',
-command => sub {
if ( $cb_value[2] == 1 ) {
&do_get( $main, $c[2] = 2 );
}
}
)->pack( -side => 'top', -anchor => 'w', -padx => 20 );

#DOEN EN EXIT BUTTONS

$bt[0] = $opbtFrm->Button(
-text => 'Toets',
-width => 8,
-height => 1,
-command => sub { &do_while }
)->pack( -side => 'left' );

$bt[1] = $opbtFrm->Button(
-text => 'Exit',
-width => 8,
-height => 1,
-command => sub { exit }
)->pack( -side => 'right' );
}

# SKEP FILE
sub processfile {
my $retval = 0;

if ( open SFILE, "> $sfile" ) {
print SFILE "n" if ($newline);
close(SFILE);
}
return $sfile;
}

# SAVE FILE WAT GESKEP IS
sub do_save {
my ($save) = @_;
my @types = (
[ "Text files", [qw/.txt .doc/] ],
[ "Text files", "", "TEXT" ],
[ "All files", "*" ]
);
$sfile = $main->getSaveFile(
-filetypes => @types,
-initialfile => 'test',
-defaultextension => '.txt'
);
print qq{You chose to save as "$sfile"n};
processfile();
}

# KRY FILE GEBRUIK GAAN WORD
sub do_get {
my ( $get, $get1 ) = @_;
my @types = (
[ "Text files", [qw/.txt .doc/] ],
[ "Text files", "", "TEXT" ],
[ "All files", "*" ]
);
$file = $main->getOpenFile(
-filetypes => @types,
-defaultextension => '.txt'
);
print qq{"jy het $file "n};
&kyk( $file, $get1 );
}

# SIT DIE OOP GEMAAKTE LEER IN SY PLEK
sub kyk {
my ( $kyk, $kyk1 ) = @_;
SWITCH: {
if ( $kyk1 == 0 ) {
$FILE0 = $file;
print qq{" file0 = $FILE0 "n};
my $op0 = $FILE0;
open( FILE0, "<$op0" ) or die "$!: $op0n yap0";
return $FILE0;
last SWITCH;
}
if ( $kyk1 == 1 ) {
$FILE1 = $file;
print qq{" file1 = $FILE1 "n};
my $op1 = $FILE1;
open( FILE1, "<$op1" ) or die "$!: $op1n yap1";
return $FILE1;
last SWITCH;
}
if ( $kyk1 == 2 ) {
$FILE2 = $file;
print qq{" file2 = $FILE2 "n};
my $op2 = $FILE2;
open( FILE2, "<$op2" ) or die "$!: $op2n yap2";
return $FILE2;
last SWITCH;
}
}
&do_while($file);
}

sub do_while {

#count lines and rewind
while(<FILE0>){$linetotal++}
seek FILE0, 0, SEEK_SET or die "Cannot rewind file: $!";

while(<FILE1>){$linetotal++}
seek FILE1, 0, SEEK_SET or die "Cannot rewind file: $!";

while(<FILE2>){$linetotal++}
seek FILE2, 0, SEEK_SET or die "Cannot rewind file: $!";

print "$linetotaln";

$progressbar = $main->ProgressBar(
-length => 200, # Actually width
-width => 20, # Actually height
-gap => 0,
-value => 0,
-colors => [0, 'pink'],
)->pack(-pady => 5, -padx => 5);

while (<FILE0>) {
my $line = $_;
chomp($line);
do_opt0($line);
if ( $line ne $token ) {
print SFILE "$token";
}
$progressbar->value($progressbar->value + (100/$linetotal) );
$main->update;
select(undef,undef,undef,.01);
}

while (<FILE1>) {
my $line = $_;
chomp($line);
do_opt1($line);
if ( $line ne $token ) {
print SFILE "$token";
}
$progressbar->value($progressbar->value + (100/$linetotal) );
$main->update;
select(undef,undef,undef,.01);
}

while (<FILE2>) {
my $line = $_;
chomp($line);
do_opt2($line);
if ( $line ne $token ) {
print SFILE "$token";
}
$progressbar->value($progressbar->value + (100/$linetotal) );
$main->update;
select(undef,undef,undef,.01);
}
}

# OPTIONS WAT GEMAAK IS ??????????
sub do_opt0 {

my $op0 ||= 0;
my $class;
my $print = 0;
my $word = $_[0];

my $sfil = $sfile;
$op0 = $FILE0;

print " $sfile ";

open( SFILE, ">>$sfil" ) or die "$!: $sfiln";

if ( $word =~ /^(.*)(s)(.*)/ ) {
$token = "$wordttt$op0n";
return $token;
} #spasies
if ( $word =~ /^(.*)(n)(n)(.*)/ ) {
$token = "$wordttt$op0n";
return $token;
} #dubbel enters
if ( $word =~ /^([a-z]+)([A-Z]+)([a-z]+)/ ) {
$token = "$wordttt$op0n";
return $token;
} #kleinHOOFklein
if ( $word =~ /^([A-Z])(.*)/ ) {
$token = "$wordttt$op0n";
return $token;
} #HOOF
if ( $word =~ /^((.*)[?|!|#|_|.](.*))/ ) {
$token = "$wordttt$op0n";
return $token;
} #vraagteken,#uitroepteken,#underscore,#iets,#iets
if ( $word =~ /^('-')(.*)/ ) {
$token = "$wordttt$op0n";
return $token;
} #koppelteken aan begin van woord
if ( $word =~ /^(.*)('-')$/ ) {
$token = "$wordttt$op0n";
return $token;
} #koppelteken aan einde van woord
if ( $word =~
/^(.*)(@|\|/|{|}|=|+|*|&|^|:|;|<|>|(|)|`|~|%|"|,)(.*)$/
)
{
$token = "$wordttt$op0n";
return $token;
} #weird leestekens
}

sub do_opt1 {

my $op0 ||= 0;
my $class;
my $print = 0;
my $word = $_[0];

my $sfil = $sfile;
$op1 = $FILE1;

print " $sfile ";

open( SFILE, ">>$sfil" ) or die "$!: $sfiln";

if ( $word =~ /^(.*)(s)(.*)/ ) {
$token = "$wordttt$op1n";
return $token;
} #spasies
if ( $word =~ /^(.*)(n)(n)(.*)/ ) {
$token = "$wordttt$op1n";
return $token;
} #dubbel enters
if ( $word =~ /^([a-z]+)([A-Z]+)([a-z]+)/ ) {
$token = "$wordttt$op1n";
return $token;
} #kleinHOOFklein
if ( $word =~ /^([A-Z])(.*)/ ) {
$token = "$wordttt$op1n";
return $token;
} #HOOF
if ( $word =~ /^((.*)[?|!|#|_|.](.*))/ ) {
$token = "$wordttt$op1n";
return $token;
} #vraagteken,#uitroepteken,#underscore,#iets,#iets
if ( $word =~ /^('-')(.*)/ ) {
$token = "$wordttt$op1n";
return $token;
} #koppelteken aan begin van woord
if ( $word =~ /^(.*)('-')$/ ) {
$token = "$wordttt$op1n";
return $token;
} #koppelteken aan einde van woord
if ( $word =~
/^(.*)(@|\|/|{|}|=|+|*|&|^|:|;|<|>|(|)|`|~|%|"|,)(.*)$/
)
{
$token = "$wordttt$op1n";
return $token;
} #weird leestekens
}

sub do_opt2 {

my $op0 ||= 0;
my $class;
my $print = 0;
my $word = $_[0];

my $sfil = $sfile;
$op2 = $FILE2;

print " $sfile ";

open( SFILE, ">>$sfil" ) or die "$!: $sfiln";

if ( $word =~ /^(.*)(s)(.*)/ ) {
$token = "$wordttt$op2n";
return $token;
} #spasies
if ( $word =~ /^(.*)(n)(n)(.*)/ ) {
$token = "$wordttt$op2n";
return $token;
} #dubbel enters
if ( $word =~ /^([a-z]+)([A-Z]+)([a-z]+)/ ) {
$token = "$wordttt$op2n";
return $token;
} #kleinHOOFklein
if ( $word =~ /^([A-Z])(.*)/ ) {
$token = "$wordttt$op2n";
return $token;
} #HOOF
if ( $word =~ /^((.*)[?|!|#|_|.](.*))/ ) {
$token = "$wordttt$op2n";
return $token;
} #vraagteken,#uitroepteken,#underscore,#iets,#iets
if ( $word =~ /^('-')(.*)/ ) {
$token = "$wordttt$op2n";
return $token;
} #koppelteken aan begin van woord
if ( $word =~ /^(.*)('-')$/ ) {
$token = "$wordttt$op2n";
return $token;
} #koppelteken aan einde van woord
if ( $word =~
/^(.*)(@|\|/|{|}|=|+|*|&|^|:|;|<|>|(|)|`|~|%|"|,)(.*)$/
)
{
$token = "$wordttt$op2n";
return $token;
} #weird leestekens
}

close(SFILE);
close(FILE0);
close(FILE1);
close(FILE2);

# SPASIE
sub do_spasie { }

# DUBBLE ENTRIES
sub do_ent { }

# KLEINHOOFKLEIN
sub do_khk { }

# HOOF
sub do_hoof { }

# KLEIN
sub do_klein { }

# VREEMDE
sub do_vr { }

# KOPPEL TEKEN BEGIN
sub do_kopb { }

# KOPPELTEKEN EINDE
sub do_kope { }

# WEIRD LEESTEKENS
sub do_weird { }
__END__





















--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html

--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Bob Showalter
Werner Otto wrote:
QUOTE
Hi All,

I have the following problem.

_Code:_
#!/usr/bin/perl
use IO::Socket;

my $host=shift @ARGV or die 'need hostname';
my $port=shift @ARGV or die 'need port number';
my $timeout=1;
my $socket=IO::Socket::INET->new(PeerAddr=> $host,
PeerPort => $port,
Proto => 'tcp',
Type => SOCK_STREAM

There's a comma missing here.

QUOTE
Timeout => defined($timeout)?$timeout:10) or die "Can't talk
to $host at $port";

When I test this on a machine that is currently switched off it takes
about a minute to timeout. I the code above I specify $timeout to be
1. Surely it sould timeout after 1 sec.

What platform and what version of Perl and IO::Socket? If I fix the missing
comma, it times out properly for me with Perl 5.6.1 on FreeBSD 4.10

Bob Showalter
Werner Otto wrote:

Keep the discussion on the list please.

QUOTE
Bob Showalter wrote:
...
What platform and what version of Perl and IO::Socket? If I fix the
missing comma, it times out properly for me with Perl 5.6.1 on
FreeBSD 4.10

SunOS 5.8  This is perl, v5.8.0 built for sun4-solaris-thread-multi -
I think

Sorry the full code:

#!/usr/bin/perl
use IO::Socket;

my $host=shift @ARGV or die 'need hostname';
my $port=shift @ARGV or die 'need port number';
my $timeout=1;
my $socket=IO::Socket::INET->new(PeerAddr=> $host,
PeerPort => $port,
Proto => 'tcp',
Type => SOCK_STREAM
Timeout => defined($timeout)?$timeout:10) or die "Can't talk
to $host at $port";

That code is still missing a comma and won't compile. Sorry I don't
understand why it isn't timing out on your system.

Bob Showalter
Ramprasad A Padmanabhan wrote:
QUOTE
I want to write a basic http download ( text/binary) script using
IO::Socket. Does anyone have any examples anywhere.


I know ,everyone must be wondering why I cant use ready modules like
LWP.
Well I want to auto transfer files to different remote machines. and
these machines ( in all flavors of unix/linux ) dont have tools like
LWP/ftp/wget/lynx etc and I cant install these on the machines

So I plan to
run Apache http on my machine with these files
run a telnet script from my machine, that will login to these machines
and 'write' a simple perl script and then run it from the remote
machine and download the necessary files

There's really a tremendous amount of stuff that goes into writing an http
client. I would try to script an ftp client session since you have telnet
access to the systems. Or, if possible, configure the systems to accept ftp
transfers originated from your central system.

Wiggins D Anconia
QUOTE
"Unless otherwise stated all methods return either a *true* or *false*
value, with *true* meaning that the operation was a success."

So sayeth the perldocs, but where is information about the error?
With docs
like this do you assume it's ${!}, or could it be that other thing (I
think I
saw something like $^E on this list - what is that?), or some package
variable?


Remember this is open source so you are free to check for yourself.
Net::SMTP inherits from Net::Cmd. Which means you can check the error
message, code, or status from the object itself through the inherited
methods, 'message', 'code', 'status'.

perldoc Net::Cmd for more

This is generally for methods that are causing some network interaction.
For other methods most likely catching an error is for an obvious
reason, if you have a question about a particular method check the
source or ask for that specific method and one of the gurus will check
what it can return...

http://danconia.org

p.s. I am not entirely sure whether no one is replying, the list is
slow, or my e-mail is busted, so if this is the 43rd reply to this post
sorry for the noise...

Bob Showalter
perl.org wrote:
QUOTE
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm,

Methinks that stuff is illegally posted copyrighted information.

Bob Showalter
perl.org wrote:
QUOTE
On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote
perl.org wrote:
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm,

Methinks that stuff is illegally posted copyrighted information.

Several people responded individually with comments like this.  If
the authors care, shouldn't they contact the ISP?  I mean, I can't
police the internet single-handedly.  And I think O'Reilly has
probably already made enough take on this particular snippet...

I thought you might be unaware, so wanted to warn you. Evidently, that's not
the case.

Perl.Org
On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote
QUOTE
perl.org wrote:
From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm,

Methinks that stuff is illegally posted copyrighted information.

Several people responded individually with comments like this. If the authors
care, shouldn't they contact the ISP? I mean, I can't police the internet
single-handedly. And I think O'Reilly has probably already made enough take
on this particular snippet...

Randy W. Sims
perl.org wrote:
QUOTE
On Fri, 2 Jul 2004 14:32:49 -0400 , Bob Showalter wrote

perl.org wrote:

From http://iis1.cps.unizar.es/Oreilly/perl/cookbook/ch04_07.htm,

Methinks that stuff is illegally posted copyrighted information.


Several people responded individually with comments like this.  If the authors
care, shouldn't they contact the ISP?  I mean, I can't police the internet
single-handedly.  And I think O'Reilly has probably already made enough take
on this particular snippet...


Online versions of many books do appear from time to time on various
sites. They generally move around. I've found this out by stumbling
across them during google searches, and then going back to that link a
day or two later and finding it gone.

Anyway, it is illegal. It is obviously so. You don't have to police the
internet. You only have to police your own behaviour.

Randy.

Randal L. Schwartz
QUOTE
"Perl" == Perl Org <[Email Removed]> writes:

Perl> Several people responded individually with comments like this.
Perl> If the authors care, shouldn't they contact the ISP? I mean, I
Perl> can't police the internet single-handedly.

No, but you can have enough sense that if the ENTIRE WORKS of authors
like me are *online*, someone is doing something wrong.

Please, don't tell me you sat there and had ABSOLUTELY NO CLUE.
What color is the sky on the planet where you come from?

So, even if you don't want to forward that to [Email Removed] (the
proper thing to do), the second best thing is REMOVE THAT LINK FROM
YOUR BOOKMARKS, and NOT SHARE IT?

Get it?

Stop taking money out of my pocket. You offend me.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +
<[Email Removed]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Bob Showalter
Thomas Browner wrote:
QUOTE
Is there away to make a perl  scripts in to a .exe and a services for
free. --

For making Windows services, see Win32::Daemon and Win32::Daemon::Simple on
CPAN.

Rod Za
Hi Charles, thank you very much for the help and the hint:

--- "Charles K. Clarkson" <[Email Removed]> wrote:
[snip]
QUOTE
We really don't need %job at all:
my @jobs;
foreach ( @lpstat ) {
next unless
/^
Q$printerE-
(d+)s+
(w+)s+d+s+w+s
(d+sw+sd+sd{2}:d{2}:d{2})
/ox;

push @jobs, {
job_name    => sprintf 'd%05d-001', $1,
job_owner  => $2,
job_date    => $3,
};
}

What the Q E /ox in the regex does ?

HTH,

Rod




__________________________________
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

Bob Showalter
perl.org wrote:
QUOTE
I have a vendor-provided OO package and a custom OO package.  The
custom package does not need a constructor.  I want to have a class
that inherits from both.  It also does not need a constructor - it
should use the constructor from the vendor-provided package.

I have a problem when my inheriting class tries to call methods my
custom superclass - it says the method is not available to the
subclass (Can't locate object method "whatever" via package).  Does
this mean all of the classes need to have constructors?

If the base class constructor is written properly, it should be inheritable.
If not, you'll have to write one.

Inheritable:

sub new {
my $class = shift;
bless {}, $class;
}

Not inheritable:

sub new {
bless {};
}

also not inheritable:

sub new {
bless {}, 'My::Class';
}

QUOTE
If so, in my
constructor, how do I explicitly call the parent constructor?

package Bar;

@ISA = qw/Foo/;

sub new {
my $class = shift;
bless Foo->new(@_), $class;
}

QUOTE
And in
the case of multiple inheritence, will it automatically call all
constructors in the ISA array?

No.

Luke Bakken
QUOTE
If so, in my
constructor, how do I explicitly call the parent constructor?

package Bar;

@ISA = qw/Foo/;

sub new {
my $class = shift;
bless Foo->new(@_), $class;
}

Wouldn't you want this instead?

package Bar;

@ISA = qw/Foo/;

sub new
{
my $s = shift;
my $class = ref($s) || $s;
my $self = $class->SUPER::new();
bless $self, $class;
return $self;
}

Perl.Org
On Tue, 6 Jul 2004 12:01:44 -0700, Bakken, Luke wrote
QUOTE

Wouldn't you want this instead?

package Bar;

@ISA = qw/Foo/;

sub new
{
my $s = shift;
my $class = ref($s) || $s;
my $self = $class->SUPER::new();
bless $self, $class;
return $self;
}

In the specific case of multiple inheritence, how do you know what SUPER even
is though? I mean, is it just the first entry in @ISA?

Charles K. Clarkson
Rod Za <[Email Removed]> wrote:

: --- "Charles K. Clarkson" <[Email Removed]> wrote:
:: next unless
:: /^
:: Q$printerE-
:: (d+)s+
:: (w+)s+d+s+w+s
:: (d+sw+sd+sd{2}:d{2}:d{2})
:: /ox;
:
: What the Q E /ox in the regex does?

The Q and E do the same thing as the 'quotemeta' function
in perl. See perlfunc.

/o at the end of a regex tells perl that the variable(s)
contained within do not change on each pass. See perlre.

/x at the end of a regex tells perl to ignore white space
added to the regex. See perlre.


Thus:

/^Q$printerE-(d+)s+(w+)s+d+s+w+s(d+sw+sd+sd{2}:d{2}:d{2})
/o;


is equivalent to:

/^
Q$printerE-
(d+)s+
(w+)s+d+s+w+s
(d+sw+sd+sd{2}:d{2}:d{2})
/ox;


The second regex still compiles and is (IMO) easier to read.


HTH,

Charles K. Clarkson
--
Mobile Homes Specialist


Bob Showalter
Ron Goral wrote:
QUOTE
Greetings -

I am having trouble locating and using modules that are not in the
current directory of a cgi script.  For this test, I know the
directory structure looks like this:

cgi-bin/test/test.cgi
cgi-bin/lib/DGStanLib.pm

Why not the straightforward:

use FindBin;
use lib "$FindBin::Bin/../lib";

(lifted directly from the FindBin docs)

Or why not allow the sysadmin to place the libs wherever he wants and use a
SetEnv directive in the web server config to pass PERL5LIB to the CGI
scripts and forego use lib altogether?

Ron Goral
QUOTE
Ron Goral wrote:
Greetings -

I am having trouble locating and using modules that are not in the
current directory of a cgi script.  For this test, I know the
directory structure looks like this:

cgi-bin/test/test.cgi
cgi-bin/lib/DGStanLib.pm

From: Bob Showalter [mailto:[Email Removed]]
Sent: Wednesday, July 07, 2004 10:39 AM
To: 'Ron Goral'; Perl Beginners
Subject: RE: Trying to locate module in parallel directory



Why not the straightforward:

use FindBin;
use lib "$FindBin::Bin/../lib";

(lifted directly from the FindBin docs)

Or why not allow the sysadmin to place the libs wherever he wants
and use a
SetEnv directive in the web server config to pass PERL5LIB to the CGI
scripts and forego use lib altogether?


This is obviously a case of me trying to make this too complex. Thank you
Bob for showing me that simpler is always better. My "ass"umption was that
$FindBin::Bin was going to locate a directory BELOW cgi-bin/test. The
straight forward method worked just fine.

Thank you.

Bob Showalter
perl.org wrote:
QUOTE
If my Perl contains ${DBI::errstr} I get warnings like this:

Ambiguous use of ${DBI::errstr} resolved to $DBI::errstr at (eval 20)
line 284.

If my Perl contains $DBI::errstr (without the braces) I don't get
these warnings.  Is there an explanation for this?

When Perl sees the ${ blah } notation, it's usually expecting "blah" to be a
scalar reference that you're dereferencing. But you're not doing that;
you're just giving the name of a symbol. You should just write it as
$DBI::errstr and leave the braces off.

It's only a warning, because Perl lets you use this notation inside double
quotes where you need to delimit the symbol name. Consider:

my $package = 'DBI';

print "The error is $package::errstrn"; # oops, doesn't work
print "The error is ${package}::errstrn"; # that does it

The latter can also be written as:

print "The error is $package::errstrn";

Bottom line is: you only need the braces inside double quotes, and even then
you don't usually need them. They are only used to tell Perl where your
identifier ends. If the identifier name is followed by a character that
can't be part of an identifier name (e.g. the backslash above), it will stop
there and no braces are needed.

Bob Showalter
perl.org wrote:
QUOTE
I can probably figure this out if I spend some time but as I was
going through it more questions were raised.

Is it possible for a Perl script to check if a subroutine exists in a
module without actually invoking that subroutine?

Not really, because of autoloading. See perldoc perlsub under the heading
"Autoloading".

QUOTE

I know there is some way to get a reference to a subroutine.  If I
can figure out how to get this reference (which I assume would be
undef or something if I try to get a reference to a subroutine that
does not exist) that would probably help, but I am not sure of the
syntax or if that's the right approach.

You can take a reference to a subroutine that doesn't yet exist! Consider:

$x = &foo; # reference to non-existant sub

print "$x is a reference to ", ref($x), "n";
eval { &$x }; # try to call the sub
warn $@ if $@;

eval qq[sub foo { print "Foo is here now!n" }]; # define the sub
&$x; # you can call it now

Outputs:

$x is a reference to CODE
Undefined subroutine &main::foo called at foo.pl line 4.
Foo is here now!

Bob Showalter
John wrote:
QUOTE
Is there any trim function that trims the spaces before and the end
of the string?

There's probably a module somewhere with such a function. You can also write
one simply.

I usually use the following:

s/^s+//, s/s+$// for $variable;

I like that form because you can list a bunch of variables and trim them
all.

A more traditional trim() function could be:

sub trim { local $_ = shift; s/^s+//, s/s+$//; $_ }

Marco
Hi, I always used PERL in UNIX environment, so it's my
first time trying to run a PERL script in Windows env
and I have a simple question to ask,
(I know how to do this in UNIX but not in windows).

I installed PERL for Windows under:
C:Z_Perl_584Perlbin
my below simple PERL script is called "simple.PL".

#!C:Z_Perl_584Perlbin
sub first() ;
sub first()
{
print( "Hello Worldn" ) ;
}

1- is my !# correct?
2- what command do I use to run the simple.pl?
3- is Win-DOS prompt the only place to run it from?
thanks so much,
Zapa.



__________________________________
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.