does anyone know how to pass in parameters from
command line to a perl script?
Is it the same as C++ where i specify an ARGV[ ]
and ARGC value or I use the @ARGV?
Sorta.
perldoc perlvar
look for the ARGV entry
does anyone know how to pass in parameters from
command line to a perl script?
Is it the same as C++ where i specify an ARGV[ ]
and ARGC value or I use the @ARGV?
Sorta.
perldoc perlvar
look for the ARGV entry
Some more bits about ARGV...
1. Shift will work on @ARGV by
Please, find me some method.
http://groups.google.com/groups?ic=1th=b1d971a887f189ca,8
I don't know of any more up to date news.
1. I want to read in a text file and match any line that begins with
three capital letters followed by a space. i.e. USD
while () {
/^[A-Z]{3} / and dostuff; # $_ contains line
}
2. I need to ignore any blank lines, lines containing all ---, lines
containing all ===.
I forgot to explain.
1. I want to read in a text file and match any line that begins with
three capital letters followed by a space. i.e. USD
while () {
will read from the file(s) you specify on the command
line when you run your perl script, ie
perl myscript.pl
$shash{student1} = join(\t, (bob, tyson, room5));
$shash{student2} = join(\t, (ron, anderson, room4));
$shash{student3} = join(\t, (dave, lee, room2));
$shash{student4} = join(\t, (tim, barker, room3));
$shash{student5} = join(\t, (roger, farley, room1));
How can I sort the hash by, for
But, if you did, I think this should work:
But then it is saturday morning. Sigh. Ignore my
attempt; use Peter's.
sub room { my $s = $shash{$_}; (split /\t/)[2] };
Wrong, twice. You wanted lastname, not room.
And the split isn't working on the right thing.
Peter's solution is clearer,
This should've worked. But why do I get a warning:
Use of uninitialized value at ./mk2_ratingchangedb.pl line 39, F
chunk 8.
Whenever you're dealing with baffling array errors
like this, always think of off-by-one.
In this case:
30 for ($i=1; ...) {
31 $dummy[$i][0]
I am apparently missing something.
Being aware of buffering, I suspect.
Various parts of the 'pipe' between your print
statements and the final destination do some
sort of buffering. You can switch some of this
off in perl by specifying:
$| = 1;
My next direction is OOP, but I have found it to be a
little beyond my grasp each time I try. Maybe with this
list's help I can get it.
First you have to unlearn.
Imagine you knew nothing about programming.
Now, I introduce a thing called a variable:
my Dog $spot;
(ok, the current
Imo, the lexical / package distinction is not always helpful
to beginners. Here's, er, my shot at explaining this...
1. { }.
The { } pairs that appear around blocks of code represent
a 'lexical scope'. This scope decides the life time of any
name declared with my/our/local.
A file and an eval
[using map to transform an old array to a new array
leaving the old one unchanged?]
Here's my best shot:
map { my $foo = $_; $foo =~ s/qux/waldo/ and $foo } @bar;
Fwiw, I just thought of a more brief and elegant way:
@newarray = map { local $_ = $_; s/foo/bar/; $_ }
needed. But in this case, the programmer
wants to reset $. (line number) as each new input file
is opened.
eof tests for end of file on the current file.
(eof() tests for end of file on the last file.)
---
Now, don't DARE tell me you didn't need to know
all this once you knew they were
Can't help much, but, fwiw:
These two are definitely completely wrong:
$mailer-open ( 'From' = 'me [EMAIL PROTECTED]',
'To' = 'you [EMAIL PROTECTED]',
'Subject' = 'Test'
) ;
$mailer-open ( From = 'me [EMAIL PROTECTED
So it would appear that the Cookbook has got a typo.
Sorta. You might want to read in the deja thread I referred you to.
[A thread from 1999. And I didn't find a correction in the
Cookbook's errata (though that could be because the
searching process is tedious and I wasn't motivated to
keep at
I'm having a very hard time figuring this out. Does
anyone have any suggestions or pointers for the best
way to go about this?
Go buy the Perl Cookbook. A truly superb book that
gives highly distilled, highly productive answers to
hundreds of standard things you will want to do like
this in a
I have been tasked to parse ~1500 log files summing a total of ~100mb
cleanly, effectively and with little impact on the system.
I'd use http://www.analog.cx unless you really have to use perl.
It would do the whole lot in a few seconds.
[analog] looks nice, but I am not sure it is suited for my needs
[because the logs I'm parsing aren't web logs]
Sorry, my brain must have slipped out of gear
while I wasn't looking.
Forget analog.
The file count doesn't seem that much. I suggest
you use opendir and cousins to process files
What is the credit protocol if... [it isn't explicitly documented]?
Ask the author.
Simplifying:
# Renumber a series of tests from the command line
perl -pi -e 's/(^\s+test\s+)\d+/ $1 . ++$count /e'
t/op/taint.t
This is what is called a one-liner.
One enters the above at a shell prompt (command line).
The perl -pi -e combo is a common one for quick one
Oops, hadn't finished.
's/(^\s+test\s+)\d+/ $1 . ++$count /e'
Breaking this down,
s/foo/bar/
means, search $_ ($_ is the current line in many
scripts) for something, and then replace what is
matched with something else.
s/foo(bar)baz/$1/
replaces foobarbaz with bar. Parens
Found the mistake for the files with the . Was using while (@ARGV) instead of
while (@ARGV).
Get 250 color business cards for FREE!
http://businesscards.lycos.com/vp/fastpath/
I don't fully understand how, when or why to use the map function -
my @file = (line 1, line 2, line 3, line 4, line 5);
my @test = map {/5/} @file;
The result when I print @test is:
1
As I understand things, this is the m/5/ being true
Sorta. It's the length of the list
What I was looking for is a way to take an
element from @foo - change it in some way,
and place it in @bar without changing the
original element of @foo but do it in one
line of code:
Well, I'd still be inclined to do something like:
@foo = @bar; for (@foo) { s/qux/waldo/ };
even
Can anyone send me any solution
to read the paragraph from a text file?
To read paragraphs (delimited by one or more blank
lines (really blank, no spaces or tabs)), change the
record separator from its default (newline) to the
null string ('').
$/ = '';
while () {
print;
}
A bit safer way to do this would be the following:
Jos is right in principle, but wrong in one detail.
Setting $/ to undef isn't the same as setting it to ''.
Setting it to undef makes the input operator
slurp the whole file.
In BASIC there are commands for
leftstring, midstring, and rightstring.
I am looking for the perl equiv for these.
Lets say i have a string 80 charecters long and i
want to insert at string position 20 for 10 charecters.
substr($EightyCharsLong, 19, 10) = 'morestring';
Yes, you can
I'm new to perl too, but I think I can help.
Sometimes a dangerous thought... ;
As far as I can tell, perlscript is embeded
right into an HTML file the same way you
do VBScript or JavaScript
If you have a web server set up appropriately
to allow this, this is true.
There are multiple
umm I don't know who sent me the \b for audible beep..
Er, I think they suggested \a...
he says the program is not even being run because
of the problem in the code abort the whole thing.
Then I suggest you execute the perl code at a
command prompt and see what you get.
I'll just answer the 'other stuff'.
##this does not work
print ($sort_order) ? 'Newest First' : 'Oldest First';
Perl sees this as a function() call followed by the rest.
Instead, do:
print $sort_order ? 'Newest First' : 'Oldest First';
In general, Perl works to minimize the number
open...or die... statement, but then i got an
internal server error 500.
You should add the following lines to your
cgi scripts:
use CGI::Carp qw(fatalsToBrowser);
And/or you should execute your perl scripts
from a command line before going through
the web server, to make sure they do
when i run my log script in unix
it runs with your permissions
when i run my log script in IE
it runs with the CGI's permissions,
as controlled by the sys admin that
set up the web server.
When this is done running will it
generate a file called sitelist.str.fo ?
Based on a quick glance at the script,
the stuff after the __END__ token is
not being used by the script.
So...
if($QWFLAT eq '')
{
print Enter QW flatfile file name - ;
chomp($QWFLAT = STDIN);
}
This
Found module at CPAN but not sure it is what I want.
MAIL::POP3Client was it. ANYone use this? Other
ideas? I have tried it but had no luck. Not
sure if I am barking up a wrong tree...
The right tree, perhaps the wrong bark.
What have you done? What happened?
Paste your code into an email
different flavours of Perl
Also check out http://cygwin.com/ which gives you
a simulated unix environment on Windows. This way
you can run identical perl setups on your w2k as on
your linux machines rather than using activestate on
the w2k machines.
foreach $field (@fld_vals) {
Means, iterate through @fld_vals. For each
cell, make $field be an alias to that cell, then
do the bracketed code that follows.
So, if you assign to $field in the code that
follows, you assign to the cell in the array too.
The code gets done once for each cell.
So by way of example what do I need
to add to my code so I can use the Strict Pragma?
Strictly speaking, just
use strict;
Beyond that, just note the error messages
that adding this generates, and go from there.
I take it that this is considered bad programing
style or is just out date
Can anyone explain [Eager / Greedy], please?
Perl's regex engine is both Eager (Leftmost start)
and Greedy (Rightmost end).
The Greedy aspect is subservient to the Eager one.
The ? stops it being Greedy but not Eager.
To get the rightmost match, you could try adding
a .* at the start of the
when I push the submit button to process the data inside the textarea
nothing happen if the textarea has a size 1.6K
Any suggestion?
Use method=put rather than method=get. The latter
often truncates the total form data to around 2k.
If this doesn't help, you should probably head over to
The #! operator does not work.
Yes, the #! operator doesn't help in getting perl
to execute (though you should still use it to set
execution options like -w etc.)
On Windows, you should use the usual Windows
ways of doing this sort of thing. I think the most
common Windows idiom is to give all
Hi, I'm getting a syntax error on the following
command
$PIDS=`ps -ef | grep $user | grep -v grep | cut -b
10-14`
You're missing the semi-colon (;) at the end?
[confusion]
Andy,
You really ought to paste in the actual code
causing the problem rather than retyping it.
While you are about it, make sure to include
the code that populates %router_tables.
(Fyi: your post came through in a tiny (illegible) font.)
#!/usr/sbin/perl
I recommend you start your scripts:
#!/usr/sbin/perl -w
use strict;
This will help identify a lot of basic mistakes.
if ($line =~ /^([^ ]+)\s+([-a-zA-Z*.]+) *$/) {
The [^] bit is the
Basically valid formats would be:
$123
$ 123
123$
123 $
This would suggest to me something like:
$CurrencyRegex = '$|foo|bar|baz';
$AmountRegex = '[\d.]+';
$prefixed = qr/($CurrencyRegex) \s* ($AmountRegex) /x;
$postfixed = qr/ ($AmountRegex) \s
ok, Appologies to all for not having included the whole thing, but
here...
The script you attached has 'i' in several places where there should be
'$i'.
Search thru it for {i}.
Here's something to get you started:
perldoc -q profile
perldoc -q memory
Enter:
perldoc perlvar
and then look at the entries for $CHILD_ERROR ($?) and $ERRNO ($!).
There can be other issues about return values, but start with the above.
Hi, I have a question regarding the following script.
[code]
Did you write the code?
This should be the output.
[data1]
However, the output is the following:
[data2]
Did you know that [data2] is near enough just [data1], twice?
Which is probably because the somethings in this code:
($router_table{i},$router_type{i}) = split(/\|/,
$router_tables{i});
All those indices should be {$i} rather than {i}.
I'm figuring it's the {i} causing the problem
You had it figured...
Take a look at http://www.masonhq.com/.
Hello,
I'm experimenting with putting a db backend on everything. What
I've
learned I am able to make a perl script that can access it and
manipulate data for it but there's one key item I'm stumped on. What
I'm trying to do is have the main
Is there any way we can use perl to execute interactive
unix commands without being prompted for arguments?
In general, just pipe into the command's standard input.
Ex:- passwd command asks for the password.
I suspected passwd might be different, so I did a
quick deja search:
/perl6plurals.pl
--
PS. I ask that any posts to this list that might affect
peoples' answers (which means just about any
posts, including flames), are initially directed to
me personally at [EMAIL PROTECTED] rather
than being sent to this list.
Forbidden
http://httpd.apache.org/docs/misc/FAQ-E.html#forbidden
#!/usr/bin/perl -w
use strict;
while () # lines from stdout or files listed on command line
{ # are read one at a time and put into $_
/\|/ and print# print lines with '|' in them
or # only executed if previous expression
false
I'd like our beginners to take home the message that you shouldn't
optimize
for performance until it's clear you need to. Otherwise you're just
wasting programmer time. Premature optimization is the root of, etc.
While I agree, it's a good idea to know why things are slow, and why
things
Tip for those posting (or even just creating)
long regexes:
If you stick a /x on the end of a regex,
whitespace in the regex is ignored, so
you can break it up into multiple lines,
indent lines as appropriate, add spaces
where nice, and comments, etc. One
thing to remember if you do this: white
the more recent
editions.
Data Munging with Perl is another option.
It has a very different feel from the above books.
It goes through its topics in a systematic fashion --
it seemed almost plodding to me, with perhaps
3 jokes in the entire book. However it remains a
high quality book
Can't locate Gnome.pm in @INC (@INC contains:
/usr/local/lib/perl5/5.6.1/i686-linux /usr/local/lib/perl5/5.6.1
/usr/local/lib/perl5/site_perl/5.6.1/i686-linux
/usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .)
at
./test.pl line 4.
BEGIN failed--compilation aborted at
I have a script that I want to try and run daily for archive purposes.
I
have no clue on constructing a proper crontab to do this. Any
information will be greatly appreciated. Thank you.
Hi Dennis,
This really has nothing at all to do with perl.
I'd answer if I knew, but, although I believe
[given a set of ranges, find items that are in range.
one way is for each range, look at each item.
runtime is proportional to sizes: range set X item set
if this is too slow, what is a faster way?]
*Design notes*
If theory bores you, skip to *Implementation notes*.
1. Changing when you
This is my connect string.
$dbh = DBI-connect(DBI:ODBC:ok,MITSOL\SQLExec);
This is the error message.
Login failed for user 'MITSOLSQLExec'.
As you can see the back slash has been omitted from
'MITSOLSQLExec'. I have tried putting two backslashes
but that dont work either.
I am trying to get [one program to pass some
info to another]
There's many ways to skin that cat!
(Apologies to my four cats).
I suggest creating a file which contains the directory name.
Can someone tell me what command I
can use to go to machines and count the
lines on a certain file?
perl -ne '/\n/ and $i++; eof and print $i' filename
where filename isn't really in s.
(Btw, be wary of using eof().
Otoh, sometimes it's just what you want.)
Your problem is a missing semicolon at the end of the
'use' line.
This makes perl think the following lines ($pop = ...)
are a series of parameters to the 'use' pragma. The
parameters to the 'use' pragma, after the first one (the
module), are a list of particular functions, variables,
etc. that
beginner ... recommended books other than the camel ...
Apparently, the original Camel had two chapters that
beginners would love -- Common Tasks in Perl and
Real Perl Programs.
Later Camels removed this sort of material.
The essence of this material, greatly expanded and
wonderfully edited
how do I tell perl to open a file for reading, do various
commands, and then output those changes to a new file???
Perl has some great one-liner shortcuts for writing filters.
First, -e lets you put perl on the command line:
perl -e ' print foo\n '
Prints
foo
Second, -p converts
This group is great, but sometimes deja's still the best source! ;
http://groups.google.com/groups?q=%22man+output%22+perl
Now, does anyone know how I can trim out the unwanted charecters from
the
output of a man page so that I can display it in a browser?
Sample as is:
NNAAMMEE
I'm not sure what you are saying your problem is,
and I may have this wrong, but since no one else
has answered, I'll have a go.
To generate a new, anonymous hash that is a
copy of an existing named hash, use {}.
Put the {} brackets around some expression that
can be seen by perl as a hash, eg:
-f and -M 0 or push @logs_old, $_ ;
oops, that should of course have been:
-f and (-M = 0 or push @logs_old, $_ );
101 - 170 of 170 matches
Mail list logo