Re: How to download WebPage source??
On Sat, 2 Nov 2002, montana wrote: > I know this is simple and I'm probably overlooking something in the > tutorial. > > How do I get perl to download the source code of a webpage so that I > can do some parsing and other things to the text? Try: use LWP::Simple; my $contents = get("http://www.dictionary.com/wordoftheday/";); If you need other functions for parsing http content, you might want to check out HTTP::Request Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Write hash of hashes to disk?
On 15 Nov 2002, Matt Simonsen wrote: > I've tried using DB_File open a hash and write a hash of hashes to disk, > but this failed. I read in Perl Cookbook to "just use it as a regular > hash" but from what I can tell this is not possible when speaking of > complex structures like a hash of hashes. > I'm not sure about that > I'm currently dumping this structure to disk in XML looping over all the > keys and values. I could read that back in to a hash each time my script > runs and update the hash, rewriting it to disk, but that would ding the > elegance of my script and so I'm trying to avoid it. This isn't exactly elegant. But it works: to write: use strict; use Data::Dumper; my $hr = {}; $hr->{foo} = "bar"; my $days = { mon => 1, tues => 2, wed => 3 }; $hr->{days} = $days; $hr->{aref} = ["a", "b", "c"]; my $file = "data_dump.txt"; open(F, ">$file") or die "Couldn't open file: $!"; print F Dumper $hr; Then to read it: use strict; use Data::Dumper; my $hr = do "data_dump.txt"; print Dumper $hr; If you need something more robust and efficient, look into the Storable module. It's quite nice. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: newbie bash questions
On 17 Nov 2002, Steve wrote: > Hi everyone, for some reason I can't seem to do basic math in this bash > script I'm creating for a class I'm taking. Here's my code > > #!/bin/bash > isec=`date +%s` > thisec=$isec*$isec-$isec > > I'm just getting the date in seconds, then trying to get a sort of > random number out of it by squaring the result, then subtracting the > original result from the squaring answer (just x²-x). I've tried putting > ('s and `s and 's and "s in all logical places in a weak attempt to > guess. > > My assignment is to create a script that can play Mastermind, the game > where there's a 4-digit number that is chosen randomly, and a person > guesses what the number is. After each guess the game tells you how many > of the numbers you picked are in the correct place (1's 10's 100's or > 1000's) and how many are in the number somewhere, but not in the correct > place. > > I've found the $RANDOM builtin, but I need to create a random number > that's 4 digits long. Any help is RIDICULOUSLY appreciated, THANKS!! > What is this bash thing you speak of? But seriously... :) you'll probably have better luck with this: http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=bash+shell+random Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: The > symbol in a variable
On Thu, 23 Aug 2001, Buffy Press wrote: > Hello, > > I am *very new* to Perl and to this list. I have a question I am hoping > someone can answer. I am looking over an existing Perl script and came > across this block of code: > > # Create the cmdfile > my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile"; > exit $? if system($runprog); > > Can anyone tell me what the > symbol means here: > > my $runprog = "$NexBase::idxBase/cmdfiles/$indexname > $cmdfile"; > > I have looked in O'Reilly's Programming Perl book and found lots of > information about the > symbol, but I could not see how it relates in > the above variable. Ok, here's what's happening. That whole section in double-quotes is being used as the parameter for the system() function, right? Just so you know, system() executes shell (command prompt) commands for you inside a perl script, e.g. system("ls -al"). In shell-speak, the > operator is something of a redirect. It has nothing to do with Perl so to speak but has to do with the external command. Think of it as an arrow. What is going to happen is that everything to the left of the 'arrow' will be redirected to where the arrow is pointing. In other words, the "$NexBase::idx..." will be fed the the standard input of the program/command "$cmdfile". One example of this could be: ModuleFoo::Blah/bin/foobar > foomailer This will (theoretically) mail someone the contents of the 'foobar' file in the specified directory. I hope this hasn't confused you even more. The short answer is that it's not a Perl thing, but rather, a shell thing. ;) Chris > > Any help is appreciated. > > Thanks, > Buffy > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Determining if a subroutine is defined...
On Fri, 24 Aug 2001, Michael Dube wrote: > Hi, > > I have a script that uses require to include additional perl scripts at > runtime. I would like to call a function if and only if that function is > defined in the required module. How would this be done? Would the define() > function work? Here's some pseudo of what I intend... any ideas? > > require runtime.pl; > > if (defined(runtimefunction)) { > runtimefunction(args); > } Can you elaborate why you wouldn't know if the function is present or not? Probably the best way is to use an eval block to see if the function can execute. Check out The Camel's extensive sections on eval(). I don't have the book on me, so I can't quote you the pages Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Determining if a subroutine is defined...
On Fri, 24 Aug 2001, Christopher Solomon wrote: > On Fri, 24 Aug 2001, Michael Dube wrote: > > > Hi, > > > > I have a script that uses require to include additional perl scripts at > > runtime. I would like to call a function if and only if that function is > > defined in the required module. How would this be done? Would the define() > > function work? Here's some pseudo of what I intend... any ideas? > > > > require runtime.pl; > > > > if (defined(runtimefunction)) { > > runtimefunction(args); > > } > > Can you elaborate why you wouldn't know if the function is present or not? > > > Probably the best way is to use an eval block to see if the function can > execute. > > Check out The Camel's extensive sections on eval(). I don't have the book > on me, so I can't quote you the pages > Ooops, I meant to include a crude example. Here's the general idiom: eval { function_foo(); }; $@ ? warn "function_foo not called!" : function_foo(); $@ will be true if the eval raises a syntax error. hope that helps, Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: replacing text, excluding what's between tags.
I'm not sure exactly what you want to do... Do you want to replace all of the marked a's: On Fri, 24 Aug 2001, Danial Magid wrote: > > This is a link to another place ^ ^ ^ or do you just want to replace the word 'a'? If you just want to replace 'bare' a's then this might work: $newline =~ s!\s+($pattern)\s+!$1!g Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Re[2]: Stripping line breaks
On Sat, 25 Aug 2001, Maxim Berlin wrote: > Hello Rory, > p.s. does anyone know, why i can not write "$a =~ s/$///g;" ? You can. $a =~ s!$/!!g; Perl just gets confused with the /'s, you have to use alternate delimiters. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Re[4]: Stripping line breaks
On Sun, 26 Aug 2001, Maxim Berlin wrote: > Hello Christopher, > > Saturday, August 25, 2001, Christopher Solomon <[EMAIL PROTECTED]> wrote: > >> p.s. does anyone know, why i can not write "$a =~ s/$///g;" ? > > CS> You can. > > CS> $a =~ s!$/!!g; > > CS> Perl just gets confused with the /'s, you have to use alternate > CS> delimiters. > ok, what about "$!" ? use @? what about "$@"? > and so on... I guess just use whatever delimiters won't get caught up in the variable name. You can use (I believe) any non-alphanumeric character as a regex delimiter. I like !, /, ^, and {} personally. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: alternative to regex when checking for captitalization
On Sat, 25 Aug 2001, Charles Lu wrote: > Does anyone know if there is a built in function that allows you to check to > see if all the characters in a string is capitalized or not? In other words > is there a way to check to see if a string is capitalized without using > regular expression? Thanks alot > Do you need to know if it's capitalized, or do you just want to make it capitalized if it isn't? If you just want to make sure text is capitalized, you can use the uc() function, or use \U and \E to bracket text. eg. $foo = "bar"; uc($foo); # $foo is now: "BAR" or $foo = "bar"; $uc_foo = "\U$foo\E"; # $uc_foo is now: "BAR"; in the latter example, \U starts the capitalization, and \E ends it. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Re[6]: Stripping line breaks
On Sun, 26 Aug 2001, Maxim Berlin wrote: > Hello Christopher, > > Sunday, August 26, 2001, Christopher Solomon <[EMAIL PROTECTED]> wrote: > > >> >> p.s. does anyone know, why i can not write "$a =~ s/$///g;" ? > >> > >> CS> You can. > >> > >> CS> $a =~ s!$/!!g; > >> > >> CS> Perl just gets confused with the /'s, you have to use alternate > >> CS> delimiters. > >> ok, what about "$!" ? use @? what about "$@"? > >> and so on... > > CS> I guess just use whatever delimiters won't get caught up in the variable > CS> name. You can use (I believe) any non-alphanumeric character as a regex > CS> delimiter. I like !, /, ^, and {} personally. > :) what if i don't know variable name? > > $! is $OS_ERROR, $ERRNO > $/ is $INPUT_RECORD_SEPARATOR, $RS > $^ is $FORMAT_TOP_NAME > If you're using a regex, like above, I can't really imagine a situation where you wouldn't know the variable name. Know what I mean? if you are using s!!!g, then surely you will know what will be, even if you don't know the contents of that variable. or am I misunderstanding you? Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Re[8]: Stripping line breaks
On Sun, 26 Aug 2001, Maxim Berlin wrote: > Hello Christopher, > > Sunday, August 26, 2001, Christopher Solomon <[EMAIL PROTECTED]> wrote: > > CS> or am I misunderstanding you? > > may be. > example: > > $regex=; chomp $regex; > $variable=; chomp $variable; > $a =~ s!$variable!$regex!; > Well, in this case, I don't see a problem. The contents of $variable (and $regex) do not matter really, so if you have the above code and you run the program and type in "$!" as either your $regex or $variable, I don't think that will cause a problem because of the way that regexes are pre-compiled (or something like that). I don't recall the intricacies of regex thingies, but I'm pretty sure (didn't test it), that your code above won't cause the problem you are asking about (regex elements interfering with the delimiters). In other words: the --contents-- of the regex elements do not interfere (I believe) with the regex delimiters, but the variable names --can--. HTH, Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Returning values from one perl module to another
On Tue, 28 Aug 2001 [EMAIL PROTECTED] wrote: > Ok. Now I can call a Perl program from another Perl program but I am > having trouble returning values back to the calling Perl program. Return > does not seem to work, Any suggestions?? > Well... It totally depends one what you are doing. It would be infinitely more helpful if you could include some of the offending code. Are these programs you have written yourself? or are they other modules or something. Perl, by default will return() the last evaluated statement in a sub. so: sub foo { $foo = 1; } if you say: $bar = foo(); $bar will equal 1. That's the general idiom. You don't need return statements, but they help you define exactly what you want to return. How exactly are you assessing whether or not values are being returned? Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: either or
On Wed, 24 Oct 2001, birgit kellner wrote: > I'm sure this has been covered billion times: > Until recently, I assumed that the binary operator "||" functions as > either-or. Now I read that it evaluates the left side and, if it evaluates > true, doesn't care about the right. So if I want to test whether either > $one or $two exists, || would be a bad choice: Yes, || is a short circuit operator, in that it will quit evaluating once it finds a true statment. > > my $one = "some"; > my $two = "stuff"; > if ($one||$two) { print "yes\n";} > else { print "no\n";} > > The if-condition would evaluate as true also if both values exist, which I > don't want. > My understanding is that either-or (i.e. excluxive or) on strings would > best be done with "xor". Is that correct? I've never needed to use XOR, but that's how I think it works. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: it works but is this right
On Tue, 11 Jun 2002, A Taylor wrote: > > $rank = $sth1->fetchrow_array(); > > Now, my question is this: is this the right way to retreive just 1 record, > using fetchrow_array(); ??? or is there a more acceptable way. This does > work, its just the 'array()' part is making me a little uneasy. > from DBI's exhaustive perldoc: "In a scalar context, fetchrow_array returns the value of the first field." Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: ?? very odd messages....
On Tue, 30 Oct 2001 [EMAIL PROTECTED] wrote: > Chris Zubrzycki <[EMAIL PROTECTED]> wrote: > > prefixed > > "by onion.perl.org (qpsmtpd/0.04) with SMTP; Tue Oct 30 16:22:25 2001 > > -" > > > Looks like there is a config error in ezmlm, this is exactly what I'm > getting (and its really confusing Exchange/Outlook -- not that that takes a > lot). > > E.g. your message to which I'm replying comes over as (everything after the > next blank line): > > by onion.perl.org (qpsmtpd/0.04) with SMTP; Tue Oct 30 16:28:50 2001 - > > does anyone know why my incomming messages form this list are prefixed > "by onion.perl.org (qpsmtpd/0.04) with SMTP; Tue Oct 30 16:22:25 2001 > -" > Well, all I can tell you is that onion (.perl.org) is the machine that the mailing list is coming from. I don't know enough about email to know why the headers you showed, look incorrect. Can you elaborate? Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: vars as key/value in a hash
On Thu, 8 Nov 2001, Tyler Cruickshank wrote: > I would like to create a hash based on data contained in a file. Can I not use a >variable as both the key and the value as shown below? When I print as shown I do >not get a value however if I write the key as:alta_guard => $names[1]then I >get the correct value printed out. > > open(NAMES, "d://perl/avalanche/names.txt") || die "Cant open names.txt\n"; > > while(){ > chomp; > @names = split(/-/); > > %stations = ( $names[0] => $names[1] ); > @names = (); > > } # End while. > > $table = 'alta_guard'; > print "Text: $stations{$table}\n"; > I'm not sure exactly what you want, but I think you want this: my %stations; while () { chomp; my @names = split(/-/); $stations{$names[0]} = $names[1]; } Chris > Thanks! > > -tyler > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp: either = | ; and = ???
On Thu, 8 Nov 2001, Louis-Philippe Dextraze wrote: > > > > hi, > I found this example on a regexp guide > (http://etext.lib.virginia.edu/helpsheets/regex.html) > > > /(^To:|^From:)/ > > this matches either TO: or From: > > can I twist this in some way to make it match only when both are there? > > example > > "the dude" > "the cat" > "name your state" > "the name of some dude" > > if (/(the|name/) > { > print "Match"; > } > > > this would match all of the string above. > > how could I but the regexp to match ONLY the strings > that contain both ? as this one > > "the name of some dude" In your first example, it looks like you might be parsing emails So the answer depends on how you are parsing your data. You could do: if (/the/ && /name/) { print "Match\n"; } but that assumes you are parsing the whole email header in one line (or at least the To: & From: fields. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: vars as key/value in a hash
On Thu, 8 Nov 2001, Christopher Solomon wrote: > On Thu, 8 Nov 2001, Tyler Cruickshank wrote: > > > I would like to create a hash based on data contained in a file. Can I not use a >variable as both the key and the value as shown below? When I print as shown I do >not get a value however if I write the key as:alta_guard => $names[1]then I >get the correct value printed out. > > > > open(NAMES, "d://perl/avalanche/names.txt") || die "Cant open names.txt\n"; > > > > while(){ > > chomp; > > @names = split(/-/); > > > > %stations = ( $names[0] => $names[1] ); > > @names = (); > > > > } # End while. > > > > $table = 'alta_guard'; > > print "Text: $stations{$table}\n"; > > > > I'm not sure exactly what you want, but I think you want this: > > my %stations; > > while () { > chomp; > my @names = split(/-/); > $stations{$names[0]} = $names[1]; > } > > Chris If this is what you want, a more fun way to write it would be: %stations = map { chomp && split(/-/) } (); That should do it all in one line. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Off-Topic (200%) - Where are you from?
On Fri, 9 Nov 2001, Etienne Marcotte wrote: > By reading the messages everyday I can guess most of us are from United > States right? And since there are not a lot of messages in (my) morning > time, probably means most are from the west coast (different timezone). > > Am I right? > > I'm from Quebec, Canada.. and you? Simi Valley, CA :-) Chris > > Sorry if it's way off topic, I hope the ones that hate OT subject > filtered *off*topic* in their emails! > > Etienne > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [Fwd: Off-Topic (200%) - Where are you from?]
On Fri, 9 Nov 2001, Scott P wrote: > Madison, Wi. > > No way, really? I went to grad school in Madison before I moved out here (California) last year. I miss it, and am thinking of moving back there within a year or so. Chris > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Updating a hash using a refernece?
On Tue, 13 Nov 2001, AMORE,JUAN (HP-Roseville,ex1) wrote: > How do I update the value pointed to by key "PAGER" from more to pg. > when using a reference only to the hash element for key "PAGER". > > > %Unix= ("SHELL" => "/bin/csh", >"PAGER" => "more", >"DB" => "mysql"); > > print "Value: ", $unix{PAGER}; $unix{PAGER} = 'foo'; see perldoc perldata for more info... Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: New Coder
On Mon, 19 Nov 2001, Etienne Marcotte wrote: > I'll be the first to answer before 10 give you the same answer: Books > > www.oreilly.com -> Learning Perl, Programming Perl, Perl Cookbook. > On the net, there are many tutorials also, try google search "perl > tutorial" > Oreilly books are very good for perl learning. I would also recommend Elements of Programming with Perl by Andrew Johnson. But I agree, I would start with Learning Perl, esp since there is a new edition out. > But for me a book works better, > > Etienne > > [EMAIL PROTECTED] wrote: > > > > Hey Calvary; > > > > I am a new programmer fresh out of logic and program development school. > > Immediately I have been thrown into an environment where I have to learn 6 > > new computer languages...one of which is PERL. Where do I start? Thanks. > > > > Neo-Genus Multimedia Studios > > Boyd White > > Database Engineer > > [EMAIL PROTECTED] > > (903)731-9644 > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how do tell a program to skip
On Tue, 20 Nov 2001, shirley wrote: > I've got a program running and extracting minimum values from the data > base, but if there is no data available for the day on the data base, the > value -999.9 is reflected. so how do I tell my program to skip the -999.9 > and then select the minimum value out of the data base. To skip while looping: next if ($value == -999.9); To keep the min value of $value: my $min; $min = $value < $min ? $value : $min; > "Your life is not a coincidence, its a reflection of You." > ** > Movalo R.S > Prediction Research > South African Weather Service > Pretoria, 0001 > Tel: 012 309 3807 > E-mail: [EMAIL PROTECTED] > Call our Weather line at 082 162 > Visit our website at : www.weathersa.co.za > > ** > > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Off-Topic (200%) - Where are you from?
On 9 Nov 2001, Randal L. Schwartz wrote: > > "Curtis" == Curtis Poe <[EMAIL PROTECTED]> writes: > > Curtis> I currently live in Portland, Oregon, USA. Recently moved > Curtis> back here from Amsterdam, the Netherlands and missing Europe > Curtis> more than I thought :( > > I own a home (two, actually) in Portland, Oregon, USA. But I live out > of a suitcase in some random city (or perhaps on a cruise ship like > next week). I miss home more than I care to announce. :( > But you must get to meet so many great people! Is the cruise ship you refer to, a Geek Cruises conference? Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Perl-ish way to construct hash
I am accepting some input values via a web form. I want to compare their values to values in the database and then update those that are different. I am using hashes to hold the values. Here's what we've got: #values sucked in from a form: $params = { report_1 => 'yes', report_2 => 'no', report_3 => 'yes', report_4 => 'yes' }; #values from the database: %compare = ( 1 => 'yes', 2 => 'no', 3 => 'no', 4 => 'no' ); (don't ask why the key names are different -- too complicated to explain :) #hash to store values to be inserted into database: my %update; So I want to have an algorithm that will compare these two hashes and extract out the values that are different, for updating. I know I can use for/foreach loops to accomplish this. But I wanted something quicker and more succinct. Here's what I have: %update = map { ($_, $params->{"report_$_"}) } grep { s/report_(\d+)/$1/ and ($params->{"report_$_"} ne $compare{$_}) } keys %$params; Now, I know this works, but I was wondering if there is a better way to do it, or maybe a more Perl-ish way. (I reduced it to this from two separate foreach loops). Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Good CS Literature
On 27 Dec 2001, Luke wrote: > Hello people... Happy Holidays... > > This is my first post. Im a senior high school student and > about to graduate this year(lets just hope hehhehe).. Im just > wondering if any of you can recommend some good Computer Science > books that most universities use...my programming skills is a > little scattered (C,Java, Perl, Python..)[ALL basic stuff]but i > still dont consider myself a programmer... > > Well, I can't comment on what literature you are likely to be exposed to in a University CS program, since many CS programs are very different and take varying approaches to teaching computer science. However, there are some books that --some-- would consider de facto standards. If you are learning C programming, Kernighan and Ritchie's "The C Programming Language" is worth it's weight in gold, if only for it's insight into the minds of it's authors. Many of your classes at the university level are likely not to be geared toward any particular language, but rather introducing more esoteric concepts and theories of programming: algorithms, data structures, compiler theory, RDBMS's etc... As far as that goes, many of the texts by Tanenbaum are common, and of course the canonical books on the essence of algorithms, etc, are those by Knuth. My advice right now would be to focus on one, or maybe two at the most, languages and learn them well. This being a Perl mailing list, maybe it's no surprise, I would suggest Perl for that. :) Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Hello make tabled form
On Thu, 3 Jan 2002, Naeemah Small wrote: > I am creating a table form. > The reason why, is because I want it to be neat. > I am using CGI.pm > > This is my first time making a form in perl. > How do I do it. read all about it with the command: perldoc CGI or search the web-> http://www.google.com/search?hl=en&q=perl+CGI.pm+form which yields (among others): http://stein.cshl.org/WWW/software/CGI Chris > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl installation problem
On Thu, 3 Jan 2002, ROry O'Connor wrote: > I'm running perl 5.6.0 that was installed when i installed redhat > 7.2. I tried to install a few extra modules with CPAN and it also > tried to upgrade me to 5.6.1, but for some reason could not > complete. I can't really tell what's going on, but some of my > modules (like DBI) don't work and I can't re-install them. I think > it has to do with a half-installed 5.6.1. I don't know what to do, > I don't want to destroy anything. Any ideas appreciated! Well, if the machine is yours, then I wouldn't worry about 'destroying' anything. I would try to install perl in one of your home directories, so that you can build it from scratch and not worry about any of the libraries or any other quirk that might be left by the perl in /usr/local/ (or /usr/bin). Here's a script that I use to install perl: #!/usr/bin/perl -w #or whatever native perl you have ### Build perl chdir "perl-5.6.1"; system("rm -f config.sh Policy.sh"); system(qq[ sh Configure -des -Dprefix="/home/user/apps/perl5.6.1" -Doptimize='-DAPPLLIB_EXP="/home/user/perl" ' -Dstartperl="#!/home/user/apps/perl" ]); system("make"); system("make install"); chdir "/usr/include"; system("/home/user/apps/perl5.6.1/bin/h2ph -r . \-d/home/user/apps/perl5.6.1/lib/site_perl/5.6.1"); Some of this might warrant explanation. You want to run this in the directory where you unpacked the tarballs (not the source directory, but the one where you typed: tar -xvzf perl-foo.tgz -- or something like that) note: substitute 'user' for your username the -Dprefix line tells perl where to build the directories. the -DAPPLLIB_EXP tells perl where to look for user built perl modules the -Dstartperl is what you want to use as the hashbang line after you run the script (and if it's successful), then you should go into the /home/user/apps directory and create a symlink to the perl executable: ln -s perl5.6.1/bin/perl perl which will allow you to call /home/user/apps/perl as your executable And that's it! It's not the best setup, depending on what you want to use it for. But it's a fairly safe setup if you want to have your own installation. I have a few different production systems that are setup like this, each with it's own apache, and mod_perl as well. Enjoy, Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: newbie question
On Thu, 3 Jan 2002, Pam Derks wrote: > I've been trying to understand program 6.21 in the Perl Cookbook, which changes URLs >to html links > here's a snippet: > > #!/usr/bin/perl > > $urls = '{http|telnet|gopher|file|wais|ftp'); > $ltrs = '\w'; > $gunk = '/#~:.?+=&%!\-'; > $punc = '.:?@\-'; > $any = "${ltrs}${gunk}${punc}"; > > I understand what $any is, but > what exactly is ${ltrs} or ${gunk} ?? > is this an anonymous hash > It's a "not too common", but sometimes necessary, way to write a variable. ${gunk} is the same as $gunk ${ltrs} is the same as $ltrs. imagine this scenario: let's say I have variable $file_name which has a filename in it (useful_commands.txt). And I want to rename it to include my username or something: chris_useful_commands.txt I could say: my $new_filename = "${user_name}_${file_name}"; I could also say: my $new_filename = $user_name . "_" $file_name; what's the difference? TMTOWTDI.. hope that helps, Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl installation problem
On Thu, 3 Jan 2002, Christopher Solomon wrote: > On Thu, 3 Jan 2002, ROry O'Connor wrote: > > > I'm running perl 5.6.0 that was installed when i installed redhat > > 7.2. I tried to install a few extra modules with CPAN and it also > > tried to upgrade me to 5.6.1, but for some reason could not > > complete. I can't really tell what's going on, but some of my > > modules (like DBI) don't work and I can't re-install them. I think > > it has to do with a half-installed 5.6.1. I don't know what to do, > > I don't want to destroy anything. Any ideas appreciated! > > > note: substitute 'user' for your username > > the -Dprefix line tells perl where to build the directories. > > the -DAPPLLIB_EXP tells perl where to look for user built perl modules > > the -Dstartperl is what you want to use as the hashbang line > I forgot to mention that you might want to include -DDEBUGGING in the Configure parameters if you want to turn on perl's powerful debugger Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: use or require?
On Fri, 4 Jan 2002, Connie Chan wrote: > I 've read some doc about the difference of require and use... > but I don't know what exactly that all means ?... what is run > time and what is compile time ? all I hope to know is. > which one will be faster and cost the minium loading vs time & > to the system, for a 1 time process. > One cool thing about 'require' is that you can read in files with it (like config files), that may have been created with real perl data structures, like Data::Dumper. Example: create a mysql.config file: #!/usr/bin/perl -w use strict; use Data::Dumper; my $href = { db_database_dsn => 'dbi:mysql:database=FOO;host=localhost', db_user => 'foo', db_pass => 'bar' }; open (F, ">mysql.config") or die "couldn't open file: $!"; print F Dumper $href; then run this script and it creates a file that looks like this: $VAR1 = { 'db_user' => 'foo', 'db_pass' => 'bar', 'db_database_dsn' => 'dbi:mysql:database=FOO;host=localhost' }; then (and this is the cool part), you can 'require' this file and assign it to a scalar (which actually becomes a hash_ref because that's what your data structure is: #!/usr/bin/perl -w use strict; #require 'eval's the file my $config = require "mysql.config"; #now $config is a hashref with your config directives print $config->{'db_user'}; print $config->{'db_pass'}; this of course one small useful feature of 'require'. I would say, in general though, you want to use 'use'. And of course, read the perldocs on both :) Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: About DBD-ODBC Module
On Tue, 8 Jan 2002, Jose Vicente wrote: > I can't install the module because I get some errors, when I read README file i find >this: > > BUILDING: > > >set-up these environment variables: > DBI_DSN The dbi data source, e.g. 'dbi:ODBC:YOUR_DSN_HERE' > DBI_USER The username to use to connect to the database > DBI_PASS The username to use to connect to the database > ODBCHOME (Unix only) The dir your driver manager is installed in > > But I don't understand what does it means? > Please if Somebody has installed this module, tell how can I do. > Where can I find this enviroment variables. > Thanks in advance. I can't tell you how to install this module, but I can sort-of explain how to setup your environment variables. Since you didn't include any info about your configuration, I'm going to assume you have a similar setup to mine :) which is FreeBSD running bash as my shell (will work the same on linux). It will be slightly different if you are using a c-based shell (csh or tcsh). Environment variables can be set from your shell config files. For 'bash', these are namely: .bashrc and .bash_profile To define environment variables, you have to have something like this in those files: ENVIRONMENT_VAR=foo; export ENVIRONMENT_VAR; so, in your case you would have: DBI_DSN=whatever_driver_you_are_using; DBI_USER=username; DBI_PASS=secret_password; ODBCHOME=the_dir_your_driver_lives_in; export DBI_DSN DBI_USER DBI_PASS ODBCHOME; then you have to re-source your shell config file: prompt $> . .bash_profile (or just login again) Note, you don't have to make these semi-permanent by adding them to your config files, you can just do it from the command line: prompt $>DBI_DSN=whatever_driver && export DBI_DSN Either way works. Hope that helps a bit (remember this will only work if you are using *nix and bash) Christopher -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to change perl form-processing script for Windows NT server?
On Wed, 9 Jan 2002, Rohesia Hamilton wrote: > Hello, > > I have recently finished my first perl script, which > processes a form, returns an html thank you page to > the submitter, sends them a confirmation email, sends > the company (whose website the form is for) an email > and appends the contents of the form to a text file. > > I used my UNIX account as I put the script together > (easy to debug) and it works perfectly from there. > > Where it is supposed to go, however, is on a Windows > NT server, so I've moved it there to try. The html > page is returned perfectly (suggesting to the > submitter that all is well, thank you) but no emails > get sent and (as far as I can tell) no text file gets > created (in my original, the text file created itself > right in the cgi-bin -- as I could access it fine, I > left it there). > I'm assuming this is the problem (though there could be others) as to why emails aren't sentB: > # Setting up to send an email to the person who > submitted the form with a cc to x-person > $emailProgram = "| /usr/sbin/sendmail -oi -t"; I don't know what mail program you would be using on your NT machine, but I doubt it's called sendmail, and I'm betting windows doesn't know what you're talking about when you use '/' to delimit directories. But I don't and have never done any development on windows... Hope that helps. Christopher -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regex for shared object files
On Thu, 10 Jan 2002, zentara wrote: > Hi, > I'm trying to find all .so.xxx files on my system. > Eventually I want to do things with them, but for > now I just want to identify them. > > I pretty much have it, except I'm lacking enough > regex knowledge to separate out the so from the .so. > files. > > I'm matching > > cursor > moc_sound > libqt.so.2 > libqt-mt.so > etc. > > It's pretty close but not clean enough. > Anyone? Thanks. Assuming you're on a *nix system, you can skip Perl altogether, and use the unix command-line tool 'find': [%prompt%] find /usr/lib -type f -print -name '*.so*' If you want to save the list to file, just redirect the output with the greater-than symbol '>' and specify a file name: [%prompt%] find /usr/lib -type f -print -name '*.so*' > some_file.txtB Of course a Perl script will work, and will even be more flexible, but if that's all you need, the unix tools work great. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regex for shared object files
On Thu, 10 Jan 2002, Christopher Solomon wrote: > > On Thu, 10 Jan 2002, zentara wrote: > > > Hi, > > I'm trying to find all .so.xxx files on my system. > > Eventually I want to do things with them, but for > > now I just want to identify them. > > > > I pretty much have it, except I'm lacking enough > > regex knowledge to separate out the so from the .so. > > files. > > > > I'm matching > > > > cursor > > moc_sound > > libqt.so.2 > > libqt-mt.so > > etc. > > > > It's pretty close but not clean enough. > > Anyone? Thanks. > > Assuming you're on a *nix system, you can skip Perl altogether, and use > the unix command-line tool 'find': > > > [%prompt%] find /usr/lib -type f -print -name '*.so*' actually, you probably want to put the print after -name '*.so*': [%prompt%] find /usr/lib -type f -name '*.so* -print or omit it the -print altogether (you may not need it). > > > If you want to save the list to file, just redirect the output with the > greater-than symbol '>' and specify a file name: > > > [%prompt%] find /usr/lib -type f -print -name '*.so*' > some_file.txtB > ditto.. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mail
On Fri, 11 Jan 2002, Pieter Blaauw wrote: > Hi guys > > How would I do the following. Platform is a Red Hat 7.2 Linux box with > Pine 4.44 as my mail client. Now pine stores all your mail in the usual > /var/spool/mail/ > > Can I use perl to extract all the mail from 2001 into another big file > that I could use as a backup of last years mail. I have over a thousand > messages in it so doing it manually is pretty impossible. I'd like to keep > the messages for this month so far in the maildir otherwise I could have > easily just moved the /var/spool/mail/ somewhere as a backup and > problem solved. Well, if the only thing you are concerned about doing is, just backing up last year's mail, then use Pine to select all the messages from 2001 and then save them in a separate folder. That folder will exist as a flat file, then you can do whatever you like to it. Tgz it, put it on CD, or whatever. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Greedy 'split' ???
On Wed, 16 Jan 2002, Scott Lutz wrote: > > $DOM_NAME, my $TLD) = split(/\./, $domain); > creates two variable out of an inputted domain name, > > until this comes along: > domainname.org.uk > > which it interprets as : > $DOM_NAME = domainname > $TLD = org > > so is it possible to do a 'greedy split' ?? This might work (untested): my $host1 = 'hr.foo.com'; my $host2 = 'web.hr.foo.com'; my $host3 = 'foo.com'; foreach my $host ($host1, $host2, $host3) { my ($dom, $tld) = (split /\./, $host)[-2, -1]; print "dom: $dom, tld: $tld\n"; } Christopher -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: array and hash assignment
On Fri, 18 Jan 2002, [iso-8859-1] amrit kumar wrote: > hi, > > what i want to proove is...supposer that i assign an > array @a = (1,2); and then i define another array @b > which is equal to @a.I have to proove that this is > done by assigning a copy of array @a to @b rather than > by reference. > > Can you help me do that...i am bit confused .. > To use your example: my @a = (1, 2); my @b = @a; print "a: @a\n"; print "b: @b\n"; $b[1] = 'foo'; print "a: @a\n"; print "b: @b\n"; run those lines of code, and you will see that altering @b, doesn't alter @a. Christopher -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: 'exists' error
I'm not well versed on the versions of Perl, but I don't think that was a particularly bug-free version. I would recommend upgrading to at least 5.005_03 Chris On Wed, 30 Jan 2002, Nikola Janceski wrote: > I have two versions of perl (5.004_04, and 5.6.1) > > it seems the older one doesn't like the following code: > > sub somefunction { > if(exists $_[0]){ > print "$_[0]\n"; > } > } > > Output of perl -c (of 5.004_4): > exists operator argument is not a HASH element at > > any ideas why the old version dies and the new version has no problems? Is > there a work around for this (without patching) for the old version? > > > Nikola Janceski > Summit Systems, Inc. > 212-896-3400 > > Testimony is like an arrow shot from a long bow; the force of it depends on > the strength of the hand that draws it. Argument is like an arrow from a > cross-bow, which has equal force though shot by a child. > -- Francis Bacon > > > > > The views and opinions expressed in this email message are the sender's > own, and do not necessarily represent the views and opinions of Summit > Systems Inc. > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Not your average system() question...
On Wed, 6 Feb 2002 [EMAIL PROTECTED] wrote: > I understand how the system command works. I understand the > difference between system() and backticks. My question is this: > I want to make a call to an external program and I want the output > printed to the command line as it is processing, BUT, I also want > the output returned to me so that I can parse and check it for certain > conditions. Basically I need the functionality of both system() and > backticks. How do I accomplish this? I looked into redirecting > STDOUT, but didnt see how it was possible. > Depending on what you want to do, this might work. open(W, "who |") or die "couldn't open pseudo-pipe: $!"; my $output; while () { $output .= $_; print; } That will print out the command as it is processing (well, as you are reading over it, so it's probably not real time, but you probably won't notice), plus it will store the output of the command in a variable which you can do stuff to. Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
is Shell.pm deprecated?
Whenever I've had to execute system or shell commands, I use the backtick operator, the system command, or filehandle half-pipes (or whatever they are called :). And I've always seen these recommended whenever someone asks how to do that. But recently, I saw the use of the Shell.pm module: use Shell qw(who); my @who = who(); and I wondered what the (dis)advantages of using it are, and why no one uses it anymore? Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: ignoring some fields in a comparision of hashes
%ignore = map { $_ => 1 } @ignore; @diff = map { $a{$_} ne $b{$_} } grep { !$ignore{$_} } keys %a; @diff will end up with a list of key/value pairs of %a that are different from %b, excluding those of %ignore. note: this is untested. Chris On 7 Feb 2002, Chas Owens wrote: > I have two hashes (%a and %b) that contain data for one person from two > different systems and I want to compare these hashes to see if the > systems are out of sync. The catch is I know that some of the fields > will always be different and I want to ignore those fields. Below is my > solution, does anyone have a better way of doing this? BTW: there are a > lot of fields currently with more being added as time goes on and the > number of fields I want to ignore will stay pretty much the same). > > > my @ignore = ("key1", "key2"); > > KEYS: foreach my $key (keys %a) { > foreach my $ignore (@ignore) { > next KEYS if $key eq $ignore; > } > if ($a{$key} ne $b{$key}) { > print "$key is different ($a{$key}, $b{$key})\n"; > } > } > > > -- > Today is Pungenday the 38th day of Chaos in the YOLD 3168 > All Hail Discordia! > > Missle Address: 33:48:3.521N 84:23:34.786W > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Array question
On Tue, 12 Feb 2002, Kevin Butters wrote: > Beginner question: > > .. > > > I have an array that I want to insert elements into. I > want to insert elements at specific points in the > array. > > Example: > > use strict: > > @week = ("Monday", "Wednesday", "Friday"); > > I want to expand the array to include Tuesday after > element 0 and Thursday after element 1 > > I thought that splice was the correct way but > apparently not. Well, it might be that a hash is really what you want, even if you don't know it yet. But if you insist on arrays: @week = ("Mon",undef,"Wed",undef,"Fri"); That will create a sort of "placeholder" for values you know you want to insert later. But probably, depending on what you want to do, a hash would be a better solution which begs the question: what do you want to do with this? Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]