You are doing your matching wrong. The only time you can refrain from using
the binding operator =~ is when it would be binding the $_ variable. In your
case, you are binding against $Ans.
Incidentally, I think you can rewrite this:
while( ( $Remainder = ($P_length%$CYLLENGTH) ) != 0 ){ #!=0
Nevermind I am completely on crack, ignore my entire last email, your putting
a scalar in a for loop threw me off. You are in fact binding against $_. I
will now retreat under a rock of embarassment and seriously re-consider my
association with the entire Perl language. What a crappy day...
May we assume that you want to apply regexes to HTML to check formedness? Or
are you wanting to detect dangerous HTML in a document? It helps to state
what your goal is. :)
A good module to check out for general HTML mangling might be CPAN's
HTML::Parser which will "recognize markup and sepa
You could use a ternary operator here:
$Ans =~ m/u/i ? print "u\n" :
$Ans =~ m/d/i ? print "d\n" :
$Ans =~ m/r/i ? print "r\n" :
(some default);
:)
>= Original Message From Mark Goland <[EMAIL PROTECTED]> =
>Hi guys,
>
>I am trying to implement a switch statment in perl. I have tryed d
You need the program name, hence the $0. But you've wrapped the path in
backticks, which Perl interprets as an OS command. I think you mean single
quotes, but double quotes are better for $0 interpolation:
my $oraProgName = "/path/to/$0";
You could also use the caller function, for example:
If you put the -w flag in your shebang line like this
#!/usr/bin/perl -w
does it still throw an exception or do the warnings work?
>= Original Message From stanley <[EMAIL PROTECTED]> =
>i use solaris and ihave no root right.the version of perl5.005_03
>
>in a simple script if i try to
I think your script is failing at the defined($line = ). So the hash
is not getting populated at all. I think this because your call to open
didn't include a <, as in
open FH, "< your_file" or die $!;
Try adding that to your open call and see if it makes a difference.
>= Original Message
Pardon my ignorance, but what's the deal? Unless it comes authored, tested
and at least partially documented, like a CPAN module for example (other than
Safe.pm ;), why take the risk of exposing one's system to some script off the
Net? Saves time? Why reinvent the wheel? How much time is sp
The following is from page 75 in the Camel:
"List assignment in scalar context returns the number of elements produced by
the expression on the right side of the assignment:
$x = ( ($a, $b) = (7,7,7) ); #set $x to 3, not 2
"
why. how.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For a
Hello everyone,
The following is from page 75 in the Camel:
"List assignment in scalar context returns the number of elements produced by
the expression on the right side of the assignment:
$x = ( ($a, $b) = (7,7,7) ); #set $x to 3, not 2
"
It goes on to explain how this is useful but fr
Supplying module names makes answering it easier to give a better answer.
Idiomatically, $self usually refers to the scalar being blessed into a class,
in other words, an object. So $self->verbose is indeed calling a method on
the object using the indirect syntax, though whether or not this m
It might help to say what module you found it in, since that would supply more
context. Most generally, it looks like $RIDLINE is going to be put into a
regular expression, perhaps something along the lines of
m/$RIDLINE/
If you are asking about the \s+ sort of notation, then you need to read
Hello,
The documentation for GetOpt::Long on CPAN includes a section on configuring
the module. Several properties of interest to be configured are auto_abbrev,
bundling, and bundling_override. Says the blurb on the bundling description,
for example:
Enabling this option will allow single-c
That's still not terribly specific. Actually the second case of zz=>aaa
throws me but looking at it, this is my *guess* (someone PLEASE correct me).
The first case is possible because (intuitively) B follows A and 'a' follows z
(in a wraparound sort of way). The wraparound causes a carry so
Not answering the question, more like adding to it. :) There was recently a
fair bit of discussion on Perl profilers. I wonder if a Profiler would be
applicable to socket info?
>= Original Message From "Jessee Parker" <[EMAIL PROTECTED]> =
>Is there a way to keep track of the number
Instead of iterating through the keys and then using the key to get the value,
it's easier on the eyes and I believe a little bit more efficient (could be
wrong there) to do it this way:
while ( (my $key, my $value) = each %yourhash ) { ... }
This saves you from having to use $hash{$key}...you
> my @ip = $ipcf =~ m/IP Address.*?:\s+(\d+)\.(\d+)\.(\d+)\.(\d+)/;
> (@ip == 4) || die "cant parse ip address from ipconfig\n";
> my $ipaddress = "$ip[0].$ip[1].$ip[2].$ip[3]";
> print "ip address = $ipaddress\n";
It seems like you are breaking up the ip only to put it ba
>My question then, is how do you pass variables to perl script from the Unix
>command line and how are those variables processed within the script? More
>than likely, the variables will need to be passed to either an array or hash.
Well, there are two main ways I know of to pass vars to Perl from
>= Original Message From James Edward Gray II <[EMAIL PROTECTED]>
=
>If you want it in hash form, as it looks from your example, just copy
>it to a hash:
>
>my %hash = @_;
Remember though that if you are passing anything in scalar context, like an
scalar or a reference, or more than one
Put
use strict;
use warnings;
at the top of most programs you ever write. As for failing calls to open(),
phrase the call like this:
open FH, "< $file" or die "Could not read $file: $!";
Once the handle is opened successfully, iterate through the file line by line
like this:
while () { ...
I also appreciated this solution but for a different reason...it made me look
up the $- and $+ variables. Very cool. I think it would be well worth the
time for me (and any beginner) to give perldoc perlvar a thorough read...
Cheers everyone,
Nathanael
>= Original Message From "Kipp, Ja
A simple, if not elegant, way of doing it assumes that you have each sequence
in its own variable, say in an array. Then:
$sequence =~ s/\n//g; #remove ALL newlines
$sequence .= "\n"; #re-add the terminal newline
>= Original Message From "Prachi Shah" <[EMAIL PROTECTED]> =
>Hmmm. One w
I've never used CGI before, I know nothing about it. Offhand though, from
looking at your actual versus expected output (opened in new window ;) , I
have to wonder if the reason you get a literal "textfield("flavour","mint") is
because you have surrounded that statement in your code with a q()
I've never used CGI before, I know nothing about it. Offhand though, from
looking at your actual versus expected output, I have to wonder if the reason
you get a literal "textfield("flavour","mint") is because you have surrounded
that statement in your code with a q() structure. In other word
First of all, if possible, use the Llama 3rd, not 2nd.
Second, can you give the expected output and the actual output.
What platform are you on, what version of perl are you using, etc?
Nathanael
"Ain't no blood in my body, it's liquid soul in my veins"
~Roots Manuva
--
To unsubscribe, e-ma
>Use placeholders:
Could you also use quote() for this?
"Ain't no blood in my body, it's liquid soul in my veins"
~Roots Manuva
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Hello all,
While reading the Cookbook, I came across the following on page 357:
"If the value assigned to a typeglob is not a reference but itself another
typeglob, then all types by that name are aliased. The types aliased in a
full typeglob assignment are scalarand format."
I have used
>Where can I find those Docs?
at your prompt (unix) type exactly what David showed you, ie.,
perldoc -f system
;)
>Brady Fausett wrote:
>
>> David,
>>
>> Ok here is a step by step of what I am trying to do.
>>
>> 1- User goes to a web page that has a file upload system on it.
>>
>> 2- User u
This idea is even simpler though not purely regex:
$yourstring =~ s/\..*//;
@result = split /-/, $yourstring;
>= Original Message From "Mark Anderson" <[EMAIL PROTECTED]> =
>-Original Question-
>
>D-2165033-10.TKB61a => D 2165033 10
>
>and
>
>4-2175587-08.TKB63a => 4 21755
>$tablename{"$table"} = {
>"table_name"=> ["$table"],
>"index_name"=> ["$index_name"],
>"columns" => ["@column_name"],
>"type" => ["$index_type"],
>"tablespace"=> ["$tablespace_name"]
>
> Thi
>I have taken a little classroom work in perl. I believe it is very possible
>to write a perl script to read a text file, strip the carriage return and
>linefeed and write it to another file.
>
>How would the script look?
Here's one way...
my $infile = 'path/file.ext';
open IN, "< $infile" or d
>= Original Message From "Henry Wong" <[EMAIL PROTECTED]> =
>Hi all, I tried using the below codes provided but i got an error saying
>"Can't locate Date/Manip.pm in @INC...etc". I reckon that the Date::Manip do
>not exist in my library. Any other alternatives for my problem below?
If you
@mailboxes is an array of array references. You have to dereference every
element before printing it.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
>> I meant, to read a line, search a string, deleting a line, etc.
These are all things that Perl is inherently great for, so in addition to the
module mentioned, it's worth stating that it is very easy to roll your own.
=)
Nathanael
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For addition
Hello,
I am trying to get the positions of every instance of a given substring within
a given superstring (DNA sequence), and currently have a
while ( $super_string =~ m/${sub_string}/gi ) { ... }
construct.
I was under the impression that the regex transmission would bump along every
charac
>Uncaught exception from user code:
>No aliases!: Invalid argument at ./zz line 3.
Well you have three arguments. If you are *sure* that the undef is not the
problem, that leaves only two to possibly be invalid. To start, try battening
down the hatches with use strict, predeclaring yo
Why is the third parameter in your dbmopen call undef? The example in perldoc
-f dbmopen is almost identical to yours except that it defines that third parm
as 0666. If the dbmfile does not already exist, it will be created with
permissions specified by that third parm.
>= Original Message
>If ($a=b) || ($a=c) || ($a=d)
That almost looks right. I believe this will do it:
if ( $a == $b || $a == $c || $a == $c ) { ... }
or, for non-numerics:
if ( $a eq $b || ... ) { ... }
Cheers,
Nathanael
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL P
Well here's an idea anyway...
I wouldn't slurp the whole file at once, I would process line by line assuming
all pertinent info per entry is a 1-liner as shown.
You could first split on | which gives portionA, portionB.
For portionA, split on white space; the second field is the time.
For por
>if($array[$x] =~ /\d{1,3}?/)
>{
>...do something
>}
>
>Unfortunately this if statement never appears to come true.
That's because you have two quantifiers specified, the {1,3} and the ?.
for (@array) {
if ( m/^\d+$/ ) { #regex breaks on decimal numbers
do something...
}
}
--
To unsubscribe
Hello all,
When trying to install modules, it's all dandy until I get to the
%make install
part and then it cacks out with an error. I need to be root to install it
into the path. How do I make install somewhere else? I can then explicity
push onto @INC within my script.
Thanks,
Nathanael
>foreach $sub (@list_of_subs) {
> &{$sub}; ##-- this is the part I am stuck on. This doesn't work
>}
I don't know the answer to your question; I'm also interested in what others
have to say. However, I have to wonder if Perl is looking at &{$sub} and
interpretting it as a command to ex
Using the /g modifier would be appropriate. Consider using the /e modifier
which causes perl to execute code in the "replace-with" part of the s///.
The following is from the Camel 3rd Ed, page 209:
s/(\d+)/$1 * 2/; #Replaces "42" with "42 * 2"
s/(\d+)/$1 * 2/e; #Replaces "42" with "84"
Chee
>I don't think I completely understand your code. When you put
>
> 'join( '|', values %hash )'
That line of code is read pretty much the way it looks. It's like saying "Ok
Perl, I want you to grab all the values in this hash and glue 'em together
with a pipe character". So for example,
Hello,
I use Perl for DNA data mining and I'm just wondering what [non-bioperl] CPAN
modules you make good use of in your work. Handling arbitrarily large/nested
data structures is the main badboy here, but science-Perlers will know already
the nature of the beast. I've hit a bit of a rut in
>scalar (@array);
>scalar (%hash);
>
>can be used to get the number of elements.
For arrays, yes. For hashes, no. scalar %hash produces something that looks
like this: 3/8, which is some measure of the number of buckets used by the
hashing algo (efficiency).
print scalar keys %hash, "\n";
w
/\[(\d+\.\d+\.\d+\.\d+)\]/
hmmm...maybe this?
/\[((?:\d+\.){3}\d+)\]/
#non-capturing parens group for {3}, nested in $1 parens
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
You might want to allow no decimal point.
/\d+\.?\d+/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
my $SQLfields = join ',', @Fields;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
>e.g. I have a file with a header - and I only need the data from line
>100 and forward where the single lines are put in to a array for further
>"treatment".
If you are SURE of consistent formedness in your input file (data will always
be at lines 100+) you could use the $. var, which holds the
#@files contains filenames, let's say with paths prepended
for $name (@files) {
if $name =~ m/.txt$/ {
open FH, "< $name" or die $!;
do something...
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
You don't need to write anything as a module per se. You can write a library
instead, which merely contains the vars, subs and the like that you re-use
often. Name it with a .pl extenstion. Then all you have to do is
require "/path/libname.pl";
at the start of your code.
--
To unsubscr
>how do I find the line with only the "<" character?
%perldoc perlre
In the meantime, you could set the record separator to <, that is,
$/ = '<';
then make a regex that captures the filename part separate from the rest.
if (/^(filenamepattern)(.*)
The reply given by Bob highlights surrounding var names within regexes with
{}, ie., /${somevar}/. And though not related to your query, as a point of
readability, consider using the big-arrow key-value notation when appropriate
as in the current example, ie.,
my %hash = (1 => 'abc',
Page 300 of the Camel 3rd ed says:
"any modifications to @INC need to occur at compile time...You can do this
with the lib pragma described in Chapter 31 or with a BEGIN block."
I think what our colleague meant by reinstalling Perl is that doing so will
enable you to tell Perl where to look fo
I suggest looking into the File::Basename module, which is bundled with perl.
Most current documentation can be found at:
http://search.cpan.org/doc/JHI/perl-5.8.0/lib/File/Basename.pm
I suppose you could also use a regex...something like this perhaps?
/.*(\\\w+)$/
cheers,
nathanael
--
T
>> 1. Can a variable store a text file with 4+ bytes
>> in size?
>
>I am under the impression that a scalar can be as big as you need. I
>*suspect* that the problem lies in limitations on the size of an part.
I was under the
I am not sure about the search-and-replace aspect; too tired to even try.
However as far as I understand, Getopt::Std only allows single digit parms
that either accept a value or are boolean for being set at all. If you want a
multi-digit parm, you need Getopt::Long. Documentation of the mos
>perl -lne'/^[[:xdigit:]]{4}(?:\.[[:xdigit:]]{4}){2}$/&&print' yourfile
>From the original question, I believe that the desired target is
0008.0e39.ad80
and lines like it in the file. From your regex, I understand the anchors, and
the quantifiers, and the clustering without capturing. Could
>equate to this m!!x attempt:
>
>21 while ( my $line = ) {
>22 while ( m!
>23 ^# # match lines that start with
>'#'
>24 CommunityID=399 # or lines that
>contain
>
Hello everyone,
I want to count hash keys. I originally tried
my $count = scalar %hash;
which when printed gave the string 411/1024. I looked this up in
perldoc perldata and sort of understand the significance of this result in
terms of buckets.
So I tried this in a driver where I varied t
Well, I am working on linux, and I started with pico but now I use vi and am
quite happy with it; fast movement, versatile copy-paste, colored syntax
toggling...it does the job. I'll have to give nedit a look though if there
are any linux offerings...people seem to be raving about it.
regards
Load the elements of an array into a hash. Then put the unique keys back into
the array; add other goodies like sorting if you need, but one barebones way
of doing it would be:
for (@array) { chomp $_; $hash{$_}++ }
@array = ();
@array = keys %hash;
--
To unsubscribe, e-mail: [EMAIL PROTECT
Hello all,
I am a relative newcomer to the language (couple of months), and I totally
love it. One way or the other, I use it almost every day in my work, and even
beyond practical applications I want to improve my Perl as much as I can. I
own the Camel 3ed, and between that and a resource-g
I'm probably not understanding what exactly you needbut...as I see it,
$err holds whatever error message that you captured with a regex. So if you
want to make a variable with the same name as the literal, dereference a
variable with the name held in $err and the new var will autovivify:
>Jul 25 10:39:12 10.0.0.1 852: 1d23h: %VOIPAAA-5-VOIP_CALL_HISTORY:
>CallLegType 2, ConnectionId 0 0 0 0, SetupTime *10:46:49.143 GMT Thu Jul
>25 2002, PeerAddress 0051122323223, PeerSubAddress , DisconnectCause 0
>, DisconnectText , ConnectTime *10:47:09.753 GMT Thu Jul 25 2002,
>DisconnectTime *
>The code is as follows:
>
>#!/usr/bin/perl
>use LWP::UserAgent;
>$ua = LWP::UserAgent->new;
>#$ua->env_proxy; # initialize from environment variables
>$ua->proxy(ftp => '172.16.0.1');
>$ua->proxy(http => '172.16.0.1');
>#$ua->no_proxy(qw(no se fi));
>my $req = HTTP::Request->new(GET => 'http://w
The $. variable holds the current line number. So you could something along
the lines of:
open TOMYFILE, "filename" or die $!;
&insert_at_line(*TOMYFILE, int); #int = what line you want to replace
##
sub insert_at_line {
my $linetoinsert = 'somemessage'
Hello all,
Here's the situation.
I work as an analyst for a genomics lab. We have a dedicated local BLAST
(http://www.ncbi.nih.gov/) server. Whether from the summer heat, or a failing
drive, or an OS bug, or some combination of various factors, our server is
crapping out too frequently. Th
perl Makefile.PL LIB=~/somedir
make
make test
make install
blah
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
I learned just today actually how to install a module when not root.
So, you have your module tarball all good to go:
>mkdir ~/lib
>tar -zxvf modulename.tar.gz
>perl Makefile.PL LIB=~/lib
>make test
>make
>make install
and you should be fine
the link where I found the above is:
http://perlmon
a bit of humour in appreciation for the help I've gotten on this mailing list.
#!/usr/bin/perl
no strict; $rules;
my %hash = (smells => 'good'); for $i (@drag) {
open EYES, "$i"."must" or warn "groovy man";
print "Once again, my hash makes me one with the Llama;"
}
close EYES and sleep;
"You
>Would trapping it an eval be what the doctor ordered?
To answer my own question, no, it would not.
#use warnings;
would be better.
=D
Hope y'all got a good chuckle out of it anyway.
"I think for my lunch tomorrow I'll make a tuna and pickle triangle bunwich."
--
To unsubscribe, e-mail: [
Bob wrote:
<=> should probably still work, because when evaluating a string
as a number, Perl will evaluate up to the first character that
doesn't look like part of a number. so "1234 x5" evalutates as
the number 1234 (stops at the space char).
*
I didn't know that. What I did after reading
Hello all,
My hash keys look something like this:
>1234 x5
So I am thinking a cmp, as opposed to <=> is best.
What I want is for the keys to be sorted as follows:
>1 x
>2 x
>3 x
..
..
..
>n x
This is what I have in my script at the moment:
my @sort_this = keys %final_list;
m
>$log="/tmp/ito.log"
>`echo Warning: some text > $log`
>
>I need to expand the "date" command somewhere in this echo command, please
>show me how.
the perl localtime function returns the same information as a unix date
command. printing to an append filehandle in perl is similar to echoing to a
>= Original Message From chris <[EMAIL PROTECTED]> =
>Given a full pathname c:\windows\system32\kernel32.dll
>
>I need to parse this into a directory, file, and extension
>
>my $fullfilename = "c:\\windows\\system32\\kernel32.dll";
>
>breaks down into the following
>
>my $dir = "c:\\window
>= Original Message From "Balint, Jess" <[EMAIL PROTECTED]> =
>Hello. What is wrong with this?
>
>perl -e 'for(1..300){sleep 1;print ".";}'
>
>It never prints anything.
>Thanks.
I wrote a script like this:
for (1..5) {
sleep 1;
print ".";
}
when i ran it, i timed it. it took
>I figure that I can use substr() to cut up a string, but how do I make it
>between words?
you can split the string on whitespace, for one.
my @array = split /\s+/, $string;
>How do I measure a string to see if it is greater than 85 characters?
my $string_len = length($string);
>Basically, if
What I am about to raise, I do so more out of wanting someone to educate me
than disagreeing for the sake of. The *that syntax shown below is unfamiliar
to me outside the context of referencing a filehandle in a subroutine params
list, where it is optional (ie., &some_sub(*STDIN)). *that remi
Try reinstalling the module perhaps. Did you use automated installation or
manual? Were there ANY problems with the install. Are you SURE you installed
it to the appropriate directory structure for referencing? I work in 5.6.0
and use the DBI module bundled with it; are there bug reports fo
81 matches
Mail list logo