If you don't specify -out the openssl command (I think, untested)
will spit the results to STDOUT, in which case you could do this:
$results = `openssl smime smime -sign -outform der -nodetach -signer
$certificate -in $encoded`;
and then you probably want to chomp $results, or parse them in
I'd love to take advantage of threading in my production environment.
The local perl expert cautions that '"common" knowledge is that
threads in perl are not production ready - i.e. are not very stable'.
perldoc perlthrtut says that the older threading (5.005) was buggy,
ithreads has been
Asif Iqbal wrote:
I can use this to get all the env variables
...
Now how can I use this trick to get all the web env variables ? I am using
apache on unix (solaris 8) ?
It's the same way. Here's code that works for me:
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
print header;
print st
I've browsed CPAN. I've Googled. I'm stumped.
I've successfully used PDF::Parse to get at PDF metadata. But I can't
get at the content. Is there a way in perl to extract the contents of a
PDF file?
Last resort will be to use pdftotext or a similar converter, but if I
can go native, so much the
John W. Krahn wrote:
Just a couple of comments if you don't mind. (I knew you wouldn't :-)
Of course not, that's how I keep on learning! :)
Due to way some file systems work I would store the file names in an
array and use the array to rename the files instead of renaming them in
the File::Fi
Barry,
I just wrote my own version of your script. Not that it's better than
yours, just different. I've learned a lot from this list by seeing how
people do things differently than me! I hope you find my version helpful.
A couple of notes about mine:
1) The directory is taken from the command
ecture being the one I was particularly missing).
There have been other packages that have not installed for me under RH9.
Mail::SpamAssassin and HTML::Parser being two. I installed perl from
source, and that helped, although I still had to force install
HTML::Parser.
Pete
--
http://emerson.
3pm from Eric Walker:
EW> I don't know if I am reading the data dumper help code right but it seems you
EW> have to provide a list of the hash keys to get the values. I need a way to
EW> just print out all keys and values no matter how many levels of hierachy there
EW> may be i
27;,
RS> );
RS>
RS> $mail{body} = <
RS> First Name: $fname
RS> Last Name: $lname
RS> Email: $email
RS> Organization: $org
RS> Scientific Interest: $sci_int
RS> Mailing List? $check
RS>
RS> sendmail(%mail) || print "Error: $Mail::Sendmail::error\n";
RS>
RS>
RS>
--
http://emerson.wss.yale.edu/perl
Pete Emerson
WSS AM&T Yale University
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Here you go, and your guess as to what prints out is right on; subroutines
don't run until they're called, and placement in this situation doesn't
affect anything.
#!/usr/bin/perl -w
use strict;
print "one\n";
sub aa {
print "two\n";
}
print "three\n";
print "four\n";
sub bb {
prin
rite, drawn heavily from the Burke book,
LW> for the edification (or amusement) of others. Again, any insight will be
LW> greatly appreciated.
--
http://emerson.wss.yale.edu/perl
Pete Emerson
WSS AM&T Yale University
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
if $var='1>>$fileName'. I was
NM> hoping there would be a simple way getting around this
NM> without using any regexps.
NM>
NM> Navid M.
NM>
NM> --- Pete Emerson <[EMAIL PROTECTED]> wrote: >
NM> Your first perl script sends '1>>$filename'
Your first perl script sends '1>>$filename' (single quotes, this is NOT a
variable) ... and you want to replace '$filename' with the contents of the
variable $filename?
If I have that correct, a regex will help:
my $string='1>>$filename'; # This is coming from your first perl script.
my $filename
t;Can't open $file: $!" if (!open INFILE, $file);
or is this a different kettle of fish?
By the way, I really appreciate that this list caters to multiple levels
of "beginners"! I've not only been helped a lot on here, but I hope I've
helped a few myself. :)
--
http://
Thanks for your code, I've gotta look up \Q to make sure I understand
what's happening, but it looks great. I'm still parsing your comments to
make sure I understand everything.
I'm not quite sure what you meant about side effects from my conditional
being frowned upon...how else do you use the ()
(@strings) {
my $success=1;
foreach my $match (@matches) {
($string=~/$match/) ? (next) : ($success=0);
last;
}
($success) ? (print "$string matches.\n") : (print "$string does not match.\n");
}
Pete
--
http://emerson.wss.yale.edu/perl
Pete Em
er;
print start_html;
print "Hello world!\n";
print end_html;
Mar 14, 2003 at 8:16am from Francesco del Vecchio:
FdV> [Fri Mar 14 17:03:11 2003] [error] [client 127.0.0.1] Premature end of script
headers: hello.pl
--
http://emerson.wss.yale.edu/perl
Pete Emerson
WSS AM&T Yale U
The length() function is what you need.
print length($num), "\n";
Mar 12, 2003 at 10:08am from David Gilden:
DG> I am looking for the $num to treated as a string and get the number of characters,
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Dan,
I can do it in one line. But I'm not convinced it's the "right" way to
do it; i.e. it seems like it's cheating:
sub rmgtlt {
$_[0] =~ s/^\<|\>$|\n|\r|\s$//g ? return $_[0] : return $_[0];
}
There's got to be a better way that doesn't use this if-then-else
approach. I'd vote for keepi
names. What I'm attempting to do is
JK> read the first file of domains and run a search based
JK> on the contents of that file against the second file
JK> of domains. Then open a completely new file writing
JK> the contents of the second file with the exception of
JK> t
r something similar like the module Mail::POP3Client
> 'Body()' function, to get the email main body of the email ??
>
> thx's
>
>
--
http://emerson.wss.yale.edu/perl
Pete Emerson
WSS AM&T Yale University
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
t;);
> }
>
> unless (open(OUTFILE, ">nospace.txt")) {
>
> die ("Cannot open output file nospace.txt.\n");
> }
>
> $line = ;
>
> while ($line ne "") {
>
> if ($line =~ / +/) {
> print OUTFILE ('"');
>
On Thu, 2003-03-06 at 09:32, Francesco del Vecchio wrote:
> If I have a string as the following:
> a xx b a x b
> and I try a m/a(.*)b/g
> $1 = xx b a x
> what have I to do to obtain two matches each of one give me
> $1 = x
#!/usr/bin/perl -w
u
Daniel,
Inside [ ] means "any of the following", so you don't use the | as an OR
in this situation. Take the | out and you should be fine. Here's my
example:
#!/usr/bin/perl -w
use strict;
my $variable1; my @variable2; my %variable3;
$variable1=1; @variable2=(1,2,3); %variable3=(1,2,3,4);
# |SOME
On Fri, 28 Feb 2003, Stefan Lidman wrote:
> > Note that you'll match on dudette and joeshmoe ... if you want an exact
> > match, you could do:
> >
> > print "$_\n" if (/^joe|dude$/);
>
> I guess you ment:
>
> print "$_\n" if (/^(?:joe|dude)$/);
>
> Otherwise it matches if it begins with 'joe'
#!/usr/bin/perl -w
use strict;
my @list = qw(fred joe bob john dude eddie rob dudette joeshmoe);
foreach (@list) {
print "$_\n" if (/joe|dude/);
}
Note that you'll match on dudette and joeshmoe ... if you want an exact
match, you could do:
print "$_\n" if (/^joe|dude$/);
On Thu, 2003-02-27 a
There are probably oodles of ways of doing this.
Here are two:
# An array slice
@[EMAIL PROTECTED];
or
# start at position 0, remove 9 elements
splice @data, 0, 9;
Pete
On Tue, 2003-02-25 at 14:39, dan wrote:
> onwards. My way of doing this was:
> shift(@data); x 9
--
To unsubscribe, e-mail
I'm not sure what might be the best way to approach this. I'm not comfy
> with an indefinite loop, where if there is some problem removing the lockfile,
> my program would wait forever. I'd rather try for a few minutes, then exit
> with some error.
>
> Any pearls of
On Wed, 19 Feb 2003, Scott, Deborah wrote:
> Does anyone know where I can get a script that looks into the contents of a
> directory and outputs the contents of the directory into a list that is
> displayed on an HTML page? (Also, the names should contain hyperlinks to
> those contents.)
Deborah,
You probably have the module you need already installed.
I did it successfully like this:
perl -e 'use Math::Complex; print log(-2.8e-05);'
On Wed, 2003-02-05 at 11:41, [EMAIL PROTECTED] wrote:
> hi all,
> i am using perl 5.8.0 on ix86. i was using an inbuilt function log().
> i am not able to g
perldoc -q sort
foreach $empNo (sort {$a<=>$b} keys %empName) {
On Tue, 2003-02-04 at 08:17, Rob wrote:
> Hi, I want to sort a hash based on the employee number; I used a foreach
> loop but it sorts the hash based on the ascii value. How would I get it
> to sort on integer values?
--
To unsu
Dan,
Here's my solution. I'm not capturing the days, hours, minutes, seconds
as I go, but I'm sure you can see how to if it's really necessary.
#!/usr/bin/perl -w
use strict;
my @list=('3d4h45m12s', '3h', '5h2m');
foreach (@list) {
my $seconds=0;
my $string=$_;
while ($string=~s/(\
Here's a sample. The trick is to turn on autoflushing ($|=1;) so that
your text gets printed out right away.
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
$|=1;
print header;
print start_html;
for (my $i=0; $i<100; $i++) {
print ".";
sleep 1;
}
print "\n";
print end_html;
On Fri
The error results of useradd appear to go to STDERR instead of STDOUT.
You can redirect them to STDOUT, and therefore capture the results, like
this:
my $username='username';
my $rescmd=`/usr/sbin/useradd -s /bin/false $username 2>&1`;
chomp $rescmd;
print "Result is $rescmd\n";
On Fri, 2003-01-3
I'd be tempted to use a hash of hash of hashes, storing it like this:
$hash{$city}{$station}{add1}=$address1
$hash{$city}{$station}{add2}=$address2
$hash{$city}{$station}{state}=$state
$hash{$city}{$station}{zip}=$zip
$hash{$city}{$station}{phone}=$phone
So my loop would look like this:
foreach my
if ($numexs=~/^\d+$/) {
# do this if $numexs contains 1 or more numbers, nothing else
} else {
}
Your regex just checks to make sure there's one number in your entire
string. Anchor it at the beginning and the end, and then use a + to say
"one or more occurances of" ...
if ($numexs=~/^[0-9]+$
I put a working test.pl in /var/www/cgi-bin.
Then I symlinked test2.pl to it.
When I loaded up test2.pl, the web page said:
Forbidden
You don't have permission to access /cgi-bin/test2.pl on this server.
Then I put this in my section of
httpd.conf: Options FollowSymLinks
Now test2 works, and th
> if ($result eq $file1)
This is checking to see if each line matches the filename itself, not the
contents of file1. You were going for the contents of $file1, correct?
Here's my stab. Read in the target files first, then match.
When it walks through the source file, it will print out the name
I'm trying to get Mail::IMAPClient working with SSL. I can get it working
fine without SSL. Here's my attempt:
# assume $server, $port, $username, $password are defined correctly
my $ssl = IO::Socket::SSL->new(Proto=>'tcp',
SSL_verify_mod=>0x00,
if ACTION1 is a subset of (killed chopped smooshed knifed) etc.etc
and ACTION2 is a subset of (with by for from) etc. etc. (or even better,
is ACTION2 always the word "by" ??) then here is my sample program:
#!/usr/bin/perl -w
use strict;
my $text='^7Kore^7Adam killed BEST I TEST by MOD_MACHINEG
How do you determine which pair(s) of words to group together? Are you
always grouping items 3 and 4, or might you sometimes want "monkey
killed" or "killed elephant" or "with stone" ? There needs to be some
way of determining when to pull out a pair and when not to.
[EMAIL PROTECTED] wrote:
b
Suppose I have the following program:
0 #!/usr/bin/perl -w
1 use strict;
2 my $var='Edit this';
3 print "Edit \$var here --> ";
4 print $var;
5 $var=; chomp $var;
6 print "\$var has a new value: $var\n";
Can I insert a line in between line 3 and 4 which will make line for
editable? i.e. right now
If I put a lot of subroutines in the BEGIN { } section, so that they
load at compile-time, what is the disadvantage?
BEGIN {
eval { require Tk; };
if ($@) {
# Do the NoGUI stuff here
exit;
}
sub LotsOfSharedSubsHere { }
}
use Tk;
print "GUI section.\n";
Lo
I think I'm going in circles. Sorry about the multiple postings.
The program barfs on 'use Tk' even though by the time I get to the 'use
Tk' the Tk module should be installed.
I tried doing require Tk; import Tk;
but then I get this message:
Bareword "MainLoop" not allowed while "strict subs" in
I think I may have answered my own question.
Is there a "better way" (TM) or a more efficient way?
eval { require Tk };
if ($@) { # module is NOT installed
# code here to make sure user is root and wants to proceed
system('perl -MCPAN -e \'CPAN::Shell->install("Tk")\'');
}
use Tk;
etc. etc.
How do I detect whether a module is installed or not?
For example, if a script is running as root, this would be useful:
if (Tk is not installed ) { # This is what I need.
print "Do you want to install the Tk perl module? (y/n) [n] >> ";
my $answer=;
exit if ($answer!~/^[Yy]/);
print "You
The following example does what is expected, i.e. prints out the word
password on its own line.
used.pm
---
$password='password';
use.pl
--
#!/usr/bin/perl
require "./used.pm";
print "$password\n";
However, as soon as I turn on warnings and strict, and declare
$password:
#!/usr/bin/per
I'm using Mail::IMAPClient to write a mail filter via IMAP.
I'd like to connect to the server using SSL.
The instructions in the man page don't help me:
$imap=Mail::IMAPClient->new(User => $user, Password => $pass, Server =>
$host);
# blah blah blah (doc's blah blah blah, not mine!)
$imap->Socket
Here's my stab at it:
#!/usr/bin/perl -w
use strict;
my %info;
open INFILE, "$ARGV[0]" or die "Can't open file: $!\n"; # Open file specified on
command line
while () {
chomp;
my ($date, @data)=split; # Capture the date, then the rest
$date=~s/_\d{4}$//; # Re
ndle.
which can be downloaded and installed from www.cpan.org. Good luck!
Pete Emerson
--
Mynd you, møøse bites Kan be pretty nasti...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
I'm using Mail::IMAPClient to get at my mailbox:
my $imap = Mail::IMAPClient->new(Server=>'my.mail.server', User=>'username', Password
=> 'password');
my $messages=$imap->unseen_count('INBOX');
print "$messages\n";
Does anybody have tips as to how to get this to work via SSL?
I'm guessing I nee
Jeff 'japhy' Pinyan wrote:
> For the task of parsing quoted strings, my book suggests the inchworm
> method:
>
> push @terms, $1 while
> /\G\s*"([^"]*)"/g or
> /\G\s*(\S+)/g;
Hmmm...mine seems to go into an infinite loop:
#!/usr/bin/perl -w
use strict;
my @terms;
$_='"one two three"
Thank you all for your quick responses.
Splitting on the " was the key.
I'm intrigued by Jon Molin's response, though:
> my @ar = ($a =~ /((?:\"[^\"]*\"|[^\s]*))\s?/g); #should be possible to remove "
> s/\"//g foreach (@ar);
> print "$_\n" foreach (@ar);
This works, too, but I don't understand w
I'd appreciate it if someone could help me wrap my brain around this one.
I've got a string like this:
$string='"one two" three "four five six"';
I'd like to wind up with an array like this:
one two
three
four five six
Essentially, I would like to split up the string on spaces, but ignore spaces
Is there a faster way to calculate the hex md5 of a file?
sub md5 {
my $file=shift;
open (FILE, $file) or die "Can't open '$file': $!";
binmode(FILE);
my $hash=Digest::MD5->new->addfile(*FILE)->hexdigest;
close FILE;
return $hash;
}
--
To unsubscribe, e-mail: [EMAIL PRO
Here is an example of what I'm doing to detect whether I've got a scalar value in my
hash
or a hash of hashes:
#!/usr/bin/perl -w
use strict;
my %hash;
$hash{name}='Pete';
$hash{color}{favorite}='Blue';
$hash{color}{car}='Silver';
$hash{color}{house}='White';
foreach my $data (keys %hash) {
i
I am parsing an HTML page which has forms on it.
I think maybe this belongs here instead of cgi-beginners?
(Note, I'm parsing the form source, not the form results!)
I am trying to extract the variable names as well as their
labels so that I can write out an SPSS file which maps
variable names t
Okay, so I'm trying to implement your radix sort, and something's going wrong.
When I turn on warnings (I'm using Perl v5.6.0) I get:
Multidimensional syntax $table[substr $_, $i, 1] not supported at ./sort3.pl line 31.
and when I turn on strict:
Can't use an undefined value as an ARRAY reference
Dave Storrs wrote:
> Hmmm...this is interesting. A friend of mine who is in the
> process of getting her graduate degree in CS/information theory stuff
> recently told me that it has been mathematically proven that no sort can
> run faster than O(n log n) unless you know something about
Jeff 'japhy' Pinyan wrote:
> Ooh, radix sort. This is a cool technique, but it has a drawback: it
> always runs in the same time. Sorting sorted data takes as long as
> sorting UNsorted data. (Or sordid data!)
I love the implementation, gotta examine it closely and your example by hand
with
Since we're on the topic of sorts, what are the arguments for
the implemented quicksort vs. a radix sort?
Pete
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
When I send mail to a certain address, the mail gets piped to my perl
script.
I'm then using Mail::Internet to extract info, including the From
header.
For me, the header looks like this
Pete Emerson <[EMAIL PROTECTED]>
1. I assume that they're all going to look different. Is tha
Well, suppose my C program does this:
$ ./cprogram
First Name: Pete
Last Name: Emerson
I could use a Perl program like this to analyse the output:
The key is that the backticks execute any executable file and store the
output.
#!/usr/bin/perl -w
use strict;
my $cstuff=`./cprogram`;
my $first
Yes, you can do it. Here's four files. First, Perl calling a C program:
chelloworld.c gcc -o chelloworld chelloworld.c
#include
int main() {
printf("Hello, World, in C!\n");
return;
}
perlprinter.pl ##
#!/usr/bin/perl
system("./chelloworld");
Now C calling a Perl pro
Stewart,
I'm guessing it can be done with split, but I used a regex to do it,
and that way
I don't have to worry about taking out the extra ", <, and >.
my $full_address='"My Name" <[EMAIL PROTECTED]>';
my ($user, $email);
print "$full_address\n";
$full_address=~/^"(.+)" <(.+)>$/;
$user=$1;
$em
If I understand your question correctly, this will work:
#!/usr/bin/perl -w
use strict;
my ($a, $b, $c, $one, $two, $three);
$a=1; $b=2; $c=3;
($one, $two, $three)=Change($a, $b, $c);
print "$one $two $three\n";
sub Change {
my ($x, $y, $z)=@_;
$x++;
$y=0;
$z=10;
return ($x, $y, $z
I'm using Perl 5.6.0 on Linux.
I've written a program to take a given directory passed in via command
line,
traverse the directory, and for each user who owns a file in that
directory,
print out their total usage.
My first attempt captured the directory using `ls -alR` and storing the
results in
Does this do the trick?
#!/usr/bin/perl -w
use strict;
my $string=q#Strip the \'slashes\' from the \"string\" if\and\only\if
they're followed by a ' or ".#;
print "Before: $string\n";
$string=~s#\\(['"])#$1#g; # match a \ followed by either a ' or ", and
replace with just the ' or "
print "After:
I wonder why the use of sprintf? I would have done it this way:
foreach (@list) { $_=":$_"; }
Is there something that the sprintf does that I'm missing, or is this
just another way to skin the same cat? Perhaps in other circumstances
sprintf is superior?
Just curious,
Pete
Etienne M
Jeff 'japhy' Pinyan wrote:
> You could go over the entries from readdir() one at a time:
>
> opendir DIR, $dir or die "can't read $dir: $!";
>
> while (defined(my $file = readdir DIR)) {
> next if $file eq '.' or $file eq '..';
> my $full = "$dir/$file";
> # ...
> }
>
> closed
Jeff 'japhy' Pinyan wrote:
> ### ick -- use opendir() and readdir(), or glob()
Okay, sounds good. I'm not quite sure how to use glob. opendir works:
opendir(DIR, "$dir");
my @ls=readdir(DIR);
closedir(DIR);
except I get the directories . and .. , which doesn't cut it for recursion.
Is the
I've written a short program to recursively delete files/directories
that haven't been modified in a certain length of time. It appears to
work, but in the interest of improving my code/coding skills, I'd like
to get any/all comments and criticisms, particularly about the way
I handled getting the
Sorry to reply to my own post, but I just looked carefully at Ondrej's solution,
and the nice thing about it is that it doesn't matter what order the columns are
in, it will always sort on the header. So his program is a lot more generic than
mine. Nice!
Pete
Pete Emerson wrote:
&
Here's my version. It's pretty straightforward, but maybe Ondrej's solution is
far better for some reason?
#!/usr/bin/perl -w
use strict;
my $inputfile; my $outputfile;
$inputfile='myinfile.txt';
$outputfile='myoutfile.txt';
open (INFILE, "$inputfile") || die "Can't open input file\n";
open (OU
Respectfully, I disagree with this:
Peter Scott wrote:
> They're bad mainly because they suggest that the author doesn't understand
> Perl well. So if I see code like that, my spidey sense starts tingling and
> I wonder how good the code is. Why would someone type unnecessary quotes
> unless t
I don't know about anybody else, but I would LOVE a blow by blow
interpretation of this (by anyone). I assume q{} and qr{} are pattern
matching, although my reference here (Nutshell) comments only briefly on q,
not qr, is that a typo? It looks like you're setting up a regular expression
ahead of t
...and just to include both .jpg and .jpeg like John's program:
opendir DIR, "./" or die "can't open $directory: $!\n";
@files = grep /jpe?g$/i, readdir DIR;
Nice code, Shawn. I must admit that my original way of doing this was even worse
than John's (by not using opendir and closedir). Zoiks. G
Martin,
Let me take a crack at it, and explain it so that it might help some
beginners, too.
I wrote this code:
$text='supernova';
if ($text=~/.n+..?.?v*./) {
print "match.\n";
}
which just takes your regular expression and applies it. The if statement is
true, I ran it just to make sure.
Brian,
If you're looking for info about CGI, here's a very simple short CGI Perl
script that will help answer your question. I'll put my comments at the end.
#!/usr/bin/perl
use CGI qw(:standard);
if (!param()) {
print header;
print start_html;
print "\n";
print "Red\n";
print "Blue\
Thanks, Ondrej and Ian for the very useful information.
A quick followup contribution, now that I understand what's going on and what to
look for:
When querying and only returning one row (see the second part of my original
message), the following appear to be equivalent:
$prep_query="SELECT date
I have some questions about the following code snippet (using DBI to
connect to MySQL):
1. $prep_query="SELECT school_name,path from student_data where
student_id=$student_id";
2. $query=$dbh->prepare($prep_query);
3. $query->execute;
4. $temp=$query->fetchall_arrayref();
5. foreach my $row (@$te
Use substr. This will leave you with 5 characters:
$text='abcdefghijklmnopqrstuvwxyz';
$text=substr $text, 0, 5;
print "$text\n";
Output:
abcde
Bruno Veldeman wrote:
> Hi,
>
> I have been looking for a function to truncate a string at a given lenght, but am
>lost.
>
> None of the functions see
Bruno,
I used CGI and LWP::Simple to get ESPN's AL East baseball standings table
and then rewrite that table into a format that I wanted. You can see it at
http://jasper.cs.yale.edu if you're curious (insert shameless plug for the Red
Sox here). But that sort of thing might help you to grab th
83 matches
Mail list logo