Re: Date::Parse and strange dates
On 25.07.2014 18:54, Chris Knipe wrote: I have the odd (very rare) case where I am given a date in an incorrect format. I already use Date::Parse to convert the dates to a unix timestamp, and it’s working incredibly well. However, on the rare case that I get incorrect dates, Date::Parse does not like them either and errors out. The formats in question that I can’t parse basically looks like Thu, 23 Oct 2008 12:06:48+0400 Note the lack of a space between the seconds and the timezone. Is there a simple quick way to fix that by means of a regex? There is, as others have pointed out. An other way would be to use a different module, that is more relaxed when interpreting dates/times to the underlying format, like the `fuzzier` Time::ParseDate (https://metacpan.org/pod/Time::ParseDate). It works for your example like in that snippet below: perl -MDate::Parse -MTime::ParseDate -E 'my $t = Thu, 23 Oct 2008 12:06:48+0400; say $t: str2time=,str2time($t), parsedate=,parsedate($t); $t =~ s/\+/ +/; say $t: str2time=,str2time($t), parsedate=,parsedate($t)' Thu, 23 Oct 2008 12:06:48+0400: str2time= parsedate=1224749208 Thu, 23 Oct 2008 12:06:48 +0400: str2time=1224749208 parsedate=1224749208 Greetings, Janek Schleicher PS: As Rob already mentioned, you should contact the author of Date::Parse also. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: balancing/distribution problem solution
Am 21.03.2014 16:42, schrieb jbiskofski: I have 6 elevators, and 50 people. These people weigh between 120 and 350lbs. How can I find the optimal way of distributing these people into the 6 elevators so that each elevator carries approximately the same weight ? Hopefully the proposed solutions are use XYZ::FOO::BAR module from cpan rather than 60 lines of crazy algorithm perl code :) Indeed there is a CPAN module https://metacpan.org/pod/Algorithm::Bucketizer that does what you want, the following snippet works decent for me. #!/usr/bin/perl use strict; use warnings; use Algorithm::Bucketizer; my $bucketizer = Algorithm::Bucketizer-new(bucketsize = 1200); # or whatever any of your cabine can transport $bucketizer-add_bucket() for 1..6; $bucketizer-add_item(120+3.5*$_ = 120+3.5*$_) for 1..60; # here I just assume an easy uniform distribution of weights, # of course here you'd have to fit your real weights in case $bucketizer-optimize(algorith = 'random', maxtime = 10); foreach my $bucket ($bucketizer-buckets()) { print join(+,$bucket-items()), =,$bucket-level(),\n; } I used the random method for optimizing as your problem will always fail when working with enough items/buckets as it as NP-hard as someone else already suggested. Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: return just a match from an array without changing the array
Am 04.03.2014 00:35, schrieb shawn wilson: So, when I do this: my $src = (grep {/.*(ARIN|APNIC).*(\n)?/; $1} @ret)[0]; I get a full line and not just the capture: # ARIN WHOIS data and services are subject to the Terms of Use When I do this: my $src = (grep {s/.*(ARIN|APNIC).*(\n)?/$1/} @ret)[0]; I get just the match but it also alters the array You can simplify your regexp to just /(ARIN|APNIC)/; I assume you intend to get the first match in the array. In case, another solution that is short, readable and only reads the array to first occurence would be: use List::Util qw/first/; my $src; first {($src) = /(ARIN|APNIC)/} @ret; or use List::Util qw/first/; my $src; first {/(ARIN|APNIC)/ and Ssrc = $1} @ret; Disadavantage: It uses a side effect in first {...} @... block, that is not the usual way. [-- From a higher point, it would be better to use lazy lists, in that case you could use just write it as [pseudocode] $src = first map {match = $1} @ret; lazy lists are only evaluated when needed, so it would stop at first match, but this isn't built in Perl5 (will be in Perl6). --] Of course, this all only matters if working with large lists :-) In addition, a third way would be to reverse first and map looking like use List::Util qw/first/; my $re = qr/(ARIN|APNIC)/; my ($src) = map {/$re/}, first {$re} @ret; allthough it is slightly odd to use map on just a 1element list. Hope, I didn't confuse you too much, Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: RegExp
Am 08.03.2014 13:50, schrieb rakesh sharma: how do you get all words starting with letter 'r' in a string. What have you tried so far? Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Delete first line when blank
Am 07.03.2014 22:58, schrieb s...@missionstclare.com: I have some text files from which I would like to remove the first line, but only if it's blank. Any hints? I tried a few things, but the results haven't quite been satisfactory. perl -pi -e '$_ = if ( $. == 1 /^\n/);' filename on command line would be my first shot. Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OO perl programming
Am 13.02.2014 21:27, schrieb Uri Guttman: actually that isn't totally true. the concepts are fairly language independent but some languages have better support for OO than others. in particular it isn't hard to do OO even assembler (which i did) in that i grouped common data together and called subs via attached pointers. the biggest feature (which i generally don't like anyway) is inheritance and that pretty much has to be in the language to be effective. Nah, unless the language is very strict, we can fake it. A good example would be nowadays Javascript that really doesn't support OO, but pretty much every framework is object oriented by working with conventions that look feel like OO. Perl itself also doesn't support naturally OO (unless you use Moose), it is more a kind of hack (as from a point of view of the language, it is just a way of how to find wich procedure has to be called mostly following a DAG - nothing more happens when we bless something), but that is flexible enough to provide everything C++ also has. Learning object oriented programming (and design) is pretty much language independent. BTW, inheritance is IMHO much overrated. Most frameworks uses OO more to simulate generic patterns, that's why languages which enables interface still feel OO and strictly OO languages like Java had to built in generics to be useable longterm. In most cases, excessive inheritance creates more problems than it solves (unless we speak about GUI programming, but nowadays even this is solved better by HTML5). It is of course important that an object has a @ISA history, but most often it is also important that it is not abused too much. As said, most often it is just an interface with some data included (what btw also isnt the internal view of Perl/PHP/... to it, there it is just a hash with knowledge of its father and an instruction to the language to find its inherited methods). OO works best when we have to develop some kind of global problems like designed by Gammas Patterns and if we think of stuff like the Factory Pattern, well, then the language and its support for OO isn't really that important. Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: OO perl programming
Am 05.02.2014 23:30, schrieb kavita kulkarni: Can somebody suggest me good book to learn/practice object oriented Perl programming. The usual answer is to study computer science. OO programming is the same independet of language. Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Gigantic file size processing error
Am 02.01.2014 18:08, schrieb David Precious: Oh, I was thinking of a wrapper that would: (a) open a new temp file (b) iterate over the source file, line-by-line, calling the provided coderef for each line (c) write $_ (potentially modified by the coderef) to the temp file (d) finally, rename the temp file over the source file Of course, it's pretty easy to write such code yourself, and as it doesn't slurp the file in, it could be considered out of place in File::Slurp. I'd be fairly surprised if such a thing doesn't already exist on CPAN, too. (If it didn't, I might actually write such a thing, as a beginner-friendly here's how to easily modify a file, line by line, with minimal effort offering.) A short look to CPAN brings out https://metacpan.org/pod/File::Inplace what looks to do what OP wants. Honestly I never used, and it can be that it has also a performance problem, but for at least I looked to it's source code and it implements it via a temporary file without saving the whole file. Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: inserting a variable server name into code
Am 19.12.2013 19:27, schrieb Rick T: The following three lines are from a program that works fine for me. # Choose template file use constant TMPL_FILE = /big/dom/xoldserver/www/templates/open_courses3.html; my $tmpl = new HTML::Template( filename = TMPL_FILE ); I wanted to make the program more portable, which means changing the name of the server. My idea was to put the following my $server = “newserver” at the beginning of the code, then have the later lines of code use this string. That way I’d only have to change the one line when moving to another server. What I tried first was use constant TMPL_FILE = /big/dom/x” . $server . “/www/templates/open_courses3.html; This gave me a syntax error, as did several variants I tried. I looked up “use constant” in Learning Perl but found the discussion over my head (I’m a beginner!), so I was hoping someone could explain a correct way to write this code if there is one. use is interpreted at first, while the normal my $var = 'xyz' declaration is interpreted at runtime. So when you use use, no variable beside other constants are set. try instead use constant SERVER = 'Newserver'; # probably better written with ss use constant TMPL_FILE = '/big/dom/x' . SERVER . '/www/templates/opencourses3.html' Greetings, Janek PS: * if you lookup perldoc use, you'll see the use Module is equivalent to BEGIN { require Module } and the BEGIN blocks are run first of all. PPS: IMHO, it's better and more convinient to rely on conventions instead of rules, so I just write constants as $CONSTANT = ; and just never change them ever again. But it still makes it easier to make stuff like you did and probably more important, we can interpolate them into a string easier, like print blablabla $CONSTAT foofofofo; Well, but that's just a matter of taste of course. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
Another way of handling is to use one of the availabe Email::* modules on CPAN. This would have the advantages of (beside you don't have to worry about details of string quoting): - better code, as you write down what you intend to do instead of how you do it - better security, as those modules already handles (hopefully) the security breaches - you don't have to think a lot of stuff other have already thought a lot about -- Don't Repeat Yourself or other ones For example [untested]: use Email::Simple; my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); print $email-as_string; Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Help needed with here documents (security?)
Am 24.10.2013 15:07, schrieb Shawn H Corey: my $email = Email::Simple-create( header = [ From = $sender_addr, To = 'ad...@tristatelogic.com', X-Server-Protocol = $server_protocol, X-Http-User-Agent = $http_user_agent, X-Http-Referer = $http_referer, X-Remote-Addr = $remote_addr, X-Remote-Host = $remote_host, ], body = $message ); Why are you using an anonymous array for the header? Wouldn't an anonymous hash be better? A hash would insist on an even number of elements. I just followed the synopsis of the documentation of this CPAN-Module as you can find it here: https://metacpan.org/pod/Email::Simple :-) I agree to you, that a ref to a hash like header = { ... } would somehow be more logic, but I didn't wrote this CPAN module. Greetings, Janek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Is there a way in PERL ......
Anadi Taylor wrote at Thu, 11 Sep 2003 13:05:30 +: I want to run a perl script that does a check and depending on the results of that check i want to run different HTML pages. For example: if the check is positive i want to run index1.htm else I want to run index2.htm can this be done ?? That's a FAQ: perldoc -q Can I do Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help on processinf Date String.
Pandey Rajeev-A19514 wrote at Wed, 10 Sep 2003 11:56:01 +0530: I have to start with input as date string which I need to process. $date1 = Wed Sep 10 15:51:50 CST 2003; $date2 = 15:52:00.885 cst Wed Sep 10 2003; Here's a complete example working with Date::Manip. use Date::Manip; my $date1 = Wed Sep 10 15:51:50 CST 2003; my $date2 = 15:52:00.885 cst Wed Sep 10 2003; print Delta_Format( DateCalc( ParseDate($date1), ParseDate($date2) ), 1, # the decimal precision %hd hours, %md minutes ago (in seconds: %sd) ago ); Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: MailSender Quotes Problem
Pablo Fischer wrote at Mon, 25 Aug 2003 23:51:47 +: I was in a final test of my script and well it fails :-), however I found that it fails in the form that Im creating the 'mail sender' object. If I do this: smtp = '$this-{SMTP_SERVER}' (single quotes for elements) I get this error when Closing the message: Can't call method Open without a package or object reference at DemoMail.pm line 218. (I have the $sender-Open in line 218) However, If I do this: smtp = $this-{SMTP_SERVER} (double quotes for elements) I'm not sure what's going on, but mainly I don't understand why you you quote at all. What about the simple smtp = $this-{SMTP_SERVER} Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp
Anton Arhipov wrote at Tue, 26 Aug 2003 13:02:00 +0300: i've a string like BLAH (guotes included). i need to control if the BLAH is in uppercase and then if it is in uppercase truncate the quotes (), so BLAH becomes BLAH. s/([A-Z]+)/$1/g; or on a POSIX operating system I would prefer the more appropriate character class s/([[:upper:]]+)/$1/g; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Benchmark times
Pablo Fischer wrote at Sun, 24 Aug 2003 01:45:42 +: This maybe its not a Perl question. I guess it ain't really not one. I have a system (with 3 classes), that works in this order: * Check in FTP for new files Time depends on the time to connect to FTP. However, the time is always independent of the programming language, thus neglioabable to your problem. * Download new Files Again independent of the programming language. * Unzip those files (.zip files) Mostly independent of the programming language, however you can always use the zip and unzip programs if a solution in a specific language, e.g. a pure Perl solution might be slower. So the time depends only on the size of files. * Each file has 3000 lines, and there are like 10 files (30,000 lines), So I need to parse the 30,000 lines and order them Do you need to parse them or do you need to sort them? However, parsing is something Perl is very good in. Thus you can simply obtain, a Perlish solution is the quickest way, so you also don't need to know how quick Perl is. Sorting is something different as there might be very quick c solution specialised to sorting on hard disks. But that depends also on the size of the files. I assume simply 30_000 lines of 100 columns each = 3_000_000 bytes = 3 MB. 3 MB would be nowadays so less that it Perl's memory wasting wouldn't create problems. Unless memory problems, common sort routines are very quick in all languages, also to Perl. * Parse File by File, and save the parssed file in a DB (MySql) Depends on the time of the database. * Check to see if I need a backup of the Zip File Depends on the check routine, but I assume it is also language independent. * Finish How good its to do this in 10 seconds? It's always possible, you'll only need a computer that is expensive enough. However, if my guess of 3 MB is right, it should be easy with nowadays desktop pcs in every language. Exists a website with benckmark running times in Perl? http://www.google.com/search?q=benchmark+perl+programming+languages Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: a real newbie question!
Robert Mark White wrote at Fri, 22 Aug 2003 23:37:48 -0600: I see the #!/usr/bin/perl -w at the top of all programs. I have read it tells perl where to run the program. No, it usually tells the (*nix) shell what program has to start - in this case /usr/bin/perl - and with what kind of arguments - -w -. The shell then passes all lines but this first one as STDIN to the called program, in this case perl. This information I assume refers to a *nix box directory structure. I am using windows and using activeperl I think that it may mean I should use #!c:/perl -w, or am I completely lost here? Well, the windows shell (dos box) doesn't interpret the shebang line #!..., so it doesn't play that important role whether /usr/bin/perl is written or c:/perl. However I personally would prefer to write #!/usr/bin/perl even on windows as it doesn't matter for windows, but is more likely to run also on *nix machines Does the #! command mean anything in windows/activeperl programing? Yes, allthough windows itself doesn't interpret this line, perl still scans it. E.g. it looks for the -w switch or any other possible arguments on the #! line. (I believe, perl expects also that the substring perl is in the #! line for interpreting, otherwise it assumes the #... line is really only a commentar) c:/perl is where it is located on my machine, or do I just do it like everyone else for standards sake? I can not imagine anyone using a *nux box wanting my programs! Why? Does your program something very operating system specific? Unless it is an extra work, it's always a good habit to work with standards and intercompability. You can't loose anything but perhaps winning in one day some time. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: quick re help
[EMAIL PROTECTED] wrote at Wed, 13 Aug 2003 15:22:59 -0600: sub quickWrap { my $data = @_[0]; You shouldn't use an array slice where you mean to use a single array element. Thanks for catching that, I should have really seen that one. No, Perl should have seen it for you. You only have to ask for: use warnings; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: System or Modules?
Pablo Fischer wrote at Tue, 05 Aug 2003 01:58:35 +: I finish a big part of a script. Cause Im working with command to 'cp', 'remove', 'move','make directories' Im using certain Modules to do that, however I would like to know whats better in perl, to use the 'system' command or to use modules? unlink rename mkdir are all Perl builtin functions (read e.g. perldoc -f unlink) that remove, move or make directories. To copy, just use the File::Copy module. The final project could be running in two years (or maybe never) in Windows or BSD (Im working in Linux) Yeah, that's my Perl Question :-) thanks! Pablo Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regex Pattern
Jeff 'Japhy' Pinyan wrote at Thu, 07 Aug 2003 20:19:22 -0400: my ($city, $state, $zip) = $line =~ /^(.*) ([A-Z]{2}) (\d{5,9})$/; This assumes the fields are separated by a space. It also only checks for AT LEAST 4 and AT MOST 9 digits, so it would let a 7-digit zip code through. If you want to be more robust, the last part of the regex could be (\d{5}(?:\d{4})?) which ensures 5 digits, and then optionally matches 4 more. Then again, maybe just (\d{9}|\d{5}) is simpler on the eyes and brain. Another approach, if you don't really care about the format of the lines, Why than not the very simple my ($city, $state, $zip) = $line =~ /(.*) (\w+) (\d+)/; The ^ and $ aren't necessary as Perl is greedy and the \w+, \d+ are enogh to get the data (also a .* would be enough) And otherwise, instead of a crypting reverse of reverse solution, I still would prefer to write something like my @col = split ' ', $line; my $zip = join ' ', @col[0..-3]; my ($state, $zip) = @col[-2,-1]; what could also be shortcutted to 2 lines :-) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Pattern search a dir of filenames: Can use a scalar inside grep?
Alan C. wrote at Thu, 07 Aug 2003 02:34:32 -0700: It's my .* attempt I don't understand, seek help on. (seek/need ability to either all files in dir opened or pattern search the files in dir with only files that meet pattern opened) [...] my $filspec = '.*'; # brings error: permission denied at line 18 my $fildir = '/Programs/NOTETA~2/DOCUME~1'; opendir(FILDIR,$fildir)|| die can't open $fildir $!; my @fils = grep /$filspec/,readdir FILDIR; Note that .* or .txt as a regular expression is different from the meaning that it has in e.g. a dir command. .txt stands for a pattern of 4 characters where the first one can be anything (except a newline) and the three following are just txt. E.g. atxt would match /.txt/. Similar .* stands for a pattern of any character that occurs zero or more often. E.g. an empty string (containing zero characters) _matches_ the pattern. In your case, I'd guess that also the pseudo directories . and .. are readout by the readdir command what has of course to fail later. I would emphasize to you to use the perl function glob. my @file = glob($filedir/$filespec); what will work with $filespec = *.txt; # Note that the star * is not redundant # or $filespec = *.*; Note also that with glob, the directory name is already in the elements of @file. For details, please read perldoc -f glob Your program should be able to rewritten as: use strict; use warnings; my $pattern = '(?=.*\bmodule\b)'; my $filespec = '*.*'; my $filedir = '/Programs/NOTETA~2/DOCUME~1'; foreach my $file (glob $filedir/$filespec) { open(FILE,$file) or die can't $!; while (FILE) { if (s/^H=($pattern)/$1/io) { print $file:$_ ; } } close FILE; } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: XML Document - DTD Validator
Simran wrote at Fri, 08 Aug 2003 10:16:42 +1000: Does anyone know of a good perl module through which i can validate XML against a given DTD. Aka, i want to be able to give a perl function/method some XML data and the DTD file location and want it to return if the XML data is valid according to the DTD. What about the standard modules for XML stuff, like: XML::Parser XML::LibXML XML::Checker XML::Simple XML::Xerces ... Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Installing Modules
sc0017 wrote at Mon, 11 Aug 2003 13:04:12 +0300: Hi all i am newbie in perl! How could i install any module i want? Read perldoc -q install and perldoc perlmodinstall Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sick of Installing CPAN modules
Nntp.Perl.Org wrote at Thu, 07 Aug 2003 13:32:39 -0700: However, the Mail::MboxParser, the one that I really need still says it need MIME::Tools. The actual module is called MIME::tools. I'm wondering if the program is so stupid that it doesn't realize this ist he same thing. Or perhaps it's not the same thing and there's a secret to installing these modules that I don't know about. I'm wondering if the author is so stupid that it doesn't realize that MIME::Tools and MIME::tools are not _same_. Only similar, but different for at least one bit. I just tried to install Mail::MboxParser on my redhat 8 system with perl -MCPAN -e 'install Mail::MboxParser' and it worked without any problems. Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [New Question] Large file line by line
Pablo Fischer wrote at Tue, 05 Aug 2003 15:43:19 +: Reading all these message about reading a 'big' file (I know that 180MB its not a big file), but what's the difference from reading like this: @file = FILE; That reads all lines of a file into the @file array. That means, at least all the amount of the file size is now needed in RAM. foreach (@file) { print $_; } and with a While? With a while loop, the program reads line by line, thus only about the line length size is allocated by the program in RAM. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help with Unlink please
Steve Grazzini wrote at Wed, 06 Aug 2003 23:38:00 -0400: On Wed, Aug 06, 2003 at 11:49:20PM -0400, perlwannabe wrote: I have made the script as simple as possible and cannot get unlink to work. unlink (c:\testdir\*030977*.*) || die unlink failed: $!; You'd need to expand the wildcards yourself: my $pat = 'c:\testdir\*030977*.*'; foreach (glob($pat)) { unlink or warn Couldn't unlink '$_': $!; } Or if you want to write it as a one liner, you can exploit that unlink also takes a list as its arguments: unlink glob c:/testdir/*030977*.* or die No files unlinked: $!; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to replace a text in a file
Vinay Thombre wrote at Tue, 05 Aug 2003 17:31:32 +0530: I am novice to Perl and learning very basic things. I want to replace a text in a file with new text. I want to do it programatically. How can I do that? What have you learned so far yet? What is your tutorial? What does it say about replacting texts in a file? What have you tried so far? What are your exact problems? I'm asking as it is simpler to write a good answer if we know more about your knowledge and the problems you are running. Especially as it is hard to believe that no example of a file changing is shown in any tutorial. I do not want to use Perl command line argumanets. Can anyone help? Well, you could e.g. do something like use strict; use warnings; open FILE, 'filename' or die Can't open file: $!; open TEMP, 'filename.bak' or die Can't open temporary file: $!; while (FILE) { s/windows/linux/; # Upgrade your system print TEMP; } close FILE; close TEMP; rename 'filename.bak', 'filename' or die Could not rename temporary to actually file: $!; Another way would be perhaps to use the module Tie::File. But why won't you use command line arguments? The whole above script could be rewritten as perl -pi -e 's/windows/linux' filename what is much easier. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: What's Better?
Pablo Fischer wrote at Thu, 31 Jul 2003 18:52:20 +: I have 10 files, each file has 3000 lines. I have two options but I need to know which option is better in disk space and in cpu (the fastest one when I need th edata): 1. Keep the 10 files in one Zip, and When its time to use them, unzip them, and start parsing and processing each one. 2. Save each file in row of a table of my Database (using MySql, so I need to use DBI), and when Its time to use it, connect to the database, and retrieve row by row. And your Perl question is ... ? Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: [solved but..] Push first 9 elements
John W. Krahn wrote at Thu, 31 Jul 2003 00:22:04 -0700: If you are just removing one element then you can use shift instead. And you are not really using $i it seems. for ( 0 .. @archivo - 4 ) { push @lista_final, shift @correos_p; push @lista_final, shift @correos_h; push @lista_final, shift @correos_y; push @lista_final, shift @correos_l; push @lista_final, shift @correos_t; push @lista_final, shift @correos_s; push @lista_final, shift @correos_o; } Let's shorten that a bit :-) for ( 0 .. @archivo - 4 ) { push @lista_final, shift @{correos_$_} for qw/p h y l t s o/; } That might be one of the rare moments where it could be correct to use symbolic references. Here it avoids having multiplied the code and logic 7 times. And IMHO it makes the code more readable as it is easier to follow the main idea :-) Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Line Numbering
johnston wrote at Fri, 01 Aug 2003 14:15:18 +0800: My stupid question number one is: When Perl processes the script, how does it identify the lines of code? ie.. If an error occurs at line 125, is that the 125'th line of actual code, or does it count every single line in the script from the beginning including remm'ed statements, blank lines etc...?? Perl counts in most cases the lines like your editor does too. (Including comments, heredocs and so on). Only evaled parts of your code get their own counting, but I assume (hope) that beginners don't work often with eval. Sometimes the line is not what we humans might expect. E.g. if if (...) { } elsif { ... } { } has a runtime error or warning in the elsif condition part, Perl might show the line nr of the if. But compared to other languages, Perl is very correct finding the right error or warning line. My reason for asking, is that with -w I get use of uninitiaized value at... errors which do not make much sense at the line numbers mentioned... Show us the code and the warning and we'll explain. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl/Tk
Frank B. Ehrenfried wrote at Wed, 30 Jul 2003 15:34:01 -0700: I have downloaded the perl/tk module Tk804.02 from CPAN.ORG. I've unzipped and untarred it and placed it and it sub-directories uner /. But my perl script can not find it. I get the response Cann't locate Tk.pm in @INC. What to do? Have you read perldoc -q install and perldoc perlmodinstall Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Case Statement
Pablo Fischer wrote at Sat, 26 Jul 2003 23:35:14 +: I need to evaluate a lot of conditionals, and of course the use of a lot of if's its not the 'right' way, so Im using something like this: CASE: { ($string == match1) do { actions.. last CASE; }; ($string == match2) do { actions.. last CASE; }; and a lot more.. } The question, where does the 'default' case starts?. The last 5 years I have been programming in C/C++/C#/Php.. C-styles languages, so in Perl, where does the 'default' case begins? You might also have a look to the Switch module (from CPAN). It makes it easier to work with good old known switch (...) { case X {...} case Y {...} case Z {...} } style. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Local variables
Pablo Fischer wrote at Sun, 27 Jul 2003 11:59:59 +: I have a Pretty class, with 15 methods (or more). I was reading a Perl Tutorial and read that I could create local variables. So In many of my methods Im using variables, but Im not declaring them like 'local $var', just like 'my $var'. So I changed a few variables from 'my' to 'local', and When I tried to see if it was working I got: [EMAIL PROTECTED] Perl]$ perl Persona.pm Global symbol $name requires explicit package name at Persona.pm line 22. Global symbol $name requires explicit package name at Persona.pm line 24. Global symbol $name requires explicit package name at Persona.pm line 25. Global symbol $name requires explicit package name at Persona.pm line 26. Execution of Persona.pm aborted due to compilation errors. Usually you will only use my and our variable declarations. my declares a variable that is scoped to the current lexical block. Allthough that might sound hard at the first time, it's just the usual variable declaration for non-global variables, like in your subroutines. With our you declare global (package scobed variables). With local you declare a localiced variation of a _global_ variable. That's not that frequent used, as you first need a global variable and then a reason why to overwrite it and finally why only at the current lexical block :-) Especially it's usually sensless to use it for subroutine arguments. Some useful and standard moments to use it are e.g. local @ARGV = *.txt; while () { # ... } local $/ = undef; my $whole_text_of_a_file = FILE; local $ENV{CLASSPATH} = path/to/a/some/java/excecutable/files; `java some.boring.java.program In the first snippet, you change the global @ARGV holding the arguments passed to the script, just to use the nice power of the operator. It would be boring to write foreach my $file (*.txt) { open FILE, $file or die ...; while (FILE) { # ... } } In the second snippet you change the global line separator to slurp whole a file in and in the third, you change an environment variable so that you can e.g. call an evil external program with a special setting. All these cases (and most of the other useful cases for local in use) have in comman, that there is a powerful use of a global variable that is so nice that it would be foolish to use non-global or different variables. Of course, you could simulate the behaviour of every local with my $old_value= $global_variable; $global_variable = $local_value; # ... $global_variable = $old_value; But as it is very boring and errorprone (and perhaps more threadsafe), the local statement is used instead. For all the rest of information, please read the already recommended perldoc perlsub Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Split FileName
Pablo Fischer wrote at Fri, 25 Jul 2003 13:49:55 +: I have a string (its an array, the array has the values that $ftp-ls(dir) returns), so $array[1] contains this: -rw-r--r-- 1 pablopablo 18944 Jul 16 21:14 File28903.zip What I would like to do is: get the date (Jul 16), the time (12:14) and the FileName, each one if a different array, like.. my ($date, $time, $fname) = $array[1]; I know that I could to it with split, I solved the problem with split( ,$array[1]); You should also consider to use my @col = split , $array[1]; # or my @col = split /\s+/, $array[1]; Allthough the first method looks very similar to your one, splitting for one blank is a special case that splits at all whitespaces doing nearly the same as the second line (but leading whitespaces are ignored). For further details, please read perldoc -f split However I would like to know if I can separeate the original string into columns, so I could access the values like: $date = $col[6]+$col[7]; The addition seems to be the wrong opparator, as you want mainly concatenate the month with the day of month. Use one of the next methods: my $date = @col[6,7]; my $date = $col[6] $col[7]; my $date = join , @col[6,7]; $time = $col[8]; $fname = $col[9]; However, there would also be a regexp solution: my ($date, $time, $fname) = $array[1] =~ /(\w\w\w \d?\d) (\d?\d:\d\d) (\S+)$/; (I don't have the feeling, that the solution is really better, but I find it always good to know that there are more than one ways to do it) Greetings, Janek PS: In any case, I would recommend you to give the variables a better name. $array[1] is not very self explaining. What about $file_listing[1]. I personally, also found it good not play around with magic numbers like 6, 7, 8, 9 in my source code, unless it is very obviously what they are doing. In your case it might be an idea to declare some constants that are selfexplicating: use constant MONTH_COL = 6; use constant DAY_COL = 7; use constant TIME_COL = 8; use constant FNAME_COL = 9; Than you can write e.g.: my $date = @col[MONTH_COL, DAY_COL]; what is much easier to maintain on a long run. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: matching file names starting with a dot (was: REGEX PROBLEM)
magelor wrote at Fri, 25 Jul 2003 11:09:03 +0200: /tmp/test/.test.txt /tmp/test/hallo.txt /tmp/test/xyz/abc.txt /var/log/ksy/123.log now i need a regex that matches all lines but the one that contains a filename starting with a point. like .test.txt. how can i do that? this is what i have: '\.(?!tgz)[^.]*$' this matches everything, but tgz at the end of a line, so '(?!\.)[^.]*$' should do the job, but it doesnt:( If you only want to guarantuee that the base filename doesn't start with a dot, you might try something like m!/(?!\.)\w+\.\w+$! # or m!/[^.]+\.\w+$! # or m!/[^/.]+$! The first both checks wether there is a *.* file (with no leading \.) after the last slash. The second checks whether the string ends on a sequence of no slashes and no dots what also does what you might want. However, in general I would propose to use a module to gain an easy understandable and robust solution: use File::Basename; # available in CPAN sub is_file_starting_with_dot { return basename($_[0]) =~ /^\./; } foreach (/tmp/test/.test.txt, /tmp/test/hallo.txt, /tmp/test/xyz/abc.txt, /var/log/ksy/123.log, ) { print $_, is_file_starting_with_dot($_) ? starts with dot : :-) ; print \n; } Best Wishes, Janek PS: It's better not to shout to the reader with an uppercase subject that isn't very detailed. I would have ignored you if it wouldn't be friday :-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: performance tuning in perl
Phil Schaechter wrote at Thu, 24 Jul 2003 15:32:49 -0700: Does anyone know of any performance tuning tools for perl? I'd like to analyze my programs to see where it is spending the most time. If anyone has any suggesstions, I'd appreciate it. Well, the simplest tool is definitly the Benchmark module. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: modifing and writing to a file
Ged wrote at Thu, 24 Jul 2003 08:00:04 +: I am very new to perl (2 days) but am finding it very rewarding. I have however stumbled across a problem hopefully somebody can help me with. I am trying to open a file, change the text from lowercase to uppercase and rewrite it to a backup file. However, I only seem to be duplicating the original file. Here is my code: $stuff=c:/ged/perl files/stuff.txt; $backup=c:/ged/perl files/stuff.bk; open STUFF, $stuff or die Cannot open $stuff for read :$!; open BACKUP, $backup or die Cannot open $backup for write :$!; while (STUFF) { s/a-z/A-Z/g; ^^ You meant tr instead. (The substitution really changes all occurrences of the string a-z to A-Z. print BACKUP $_; Please read perldoc -q 'What\'s wrong with always quoting $vars' } However, there is a shorter other way, as Perl has a builtin uppercase function: while (STUFF) { print BACKUP, uc; } Please read perldoc -f uc for details. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Removing duplicate lines.
Jonathan Musto wrote at Mon, 21 Jul 2003 13:11:10 +0100: I have a text file which contains a list of companies: NORTH DOWN AND ARDS INSTITUTE NOTTINGHAM HEALTH AUTHORITY 1ST CONTACT GROUP LTD 1ST CONTACT GROUP LTD 1ST CONTACT GROUP LTD 1ST CONTACT GROUP LTD 4D TELECOM KINGSTON INMEDIA A E COOK LTD A E COOK LTD etc.. How can a write a simple perl script to remove the duplicates and leave just one of each customer? Any help would be great. What have you tried so far? Have you read perldoc -q duplicate [untested] my %seen; while () { print unless $seen{$_}++; } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Assigning a singe value to a list
Paul D. Kraus wrote at Thu, 17 Jul 2003 15:33:11 -0400: Is there a way to assign a single value to a list? other then doing the obvious and spelling out each list assignment or running through a loop. For instance... my ( $var1, $var2, $var3, ... ) = Paul assigning paul to all variables in the list. or a more useful example my ($passed1, $passed2, ... ) = shift As you know how many items are on the left side of the list, you can use the x operator: my ( $var1, $var2, $var3, $var4 ) = (Paul) x 4; That works the same with shift. But note that in this way, $passed1 would be equal to $passed2 and so on If you wanted to have $passed1 with the first passed argument, $passed2 with the second one and so on, you should use the @_ array directly: my ($passed1, $passed2, $passed3 ) = @_; BTW: If you would have an array instead of a list at the left side, everything becomes easier: $_ = a value foreach @array; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Is there a simple way to include source code I've written in other files?
Jamie Risk wrote at Thu, 17 Jul 2003 10:39:56 -0400: Until now, I've avoided writing modules by inlining the deisred code in the new files. Messy. I'm avoiding modules for two reasons, laziness and naive conception that for what I'm trying to do it's overkill. Is there a method to reference code in other files, like, a simple include? You can also check out perldoc -f do EXPR Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regular Expression (fwd)
Trensett wrote at Wed, 16 Jul 2003 18:29:51 -0500: The next will work: my @variable = $string =~ /\((.*?)\)/g; what's the exact implication of .*?? Why wouldn't just .* in parenthesis work for this case? A good answer can also be found in perldoc perlre and perldoc -q greedy Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Porting perl scripts on windows
Sharad Gupta wrote at Wed, 16 Jul 2003 21:03:49 -0700: Ok, Let me try to put it the other way. Any good books on how to learn perl on windows??. What about Learning Perl on Win32 Systems by Randal L. Schwartz, Tom Christiansen, Erik Olsen from O'Reilly Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regular Expression
Nick Diel wrote at Tue, 15 Jul 2003 11:12:18 -0600: I am having a hard time getting a regular expression to work the way i want it to. Take the following text: bla bla bla (la la) bla bla (di da) I want to extract the la la to one variable and di da to antoher variable. What I have tried so far is using match variables, but so far I am only able to match either just la la or la la) bla bla (di da. It would be better if you show us not only a description of your code, but your real code. The next will work: my @variable = $string =~ /\((.*?)\)/g; Now $variable[0] contains 'la la' and $variable[1] ' di da'. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl on Visual studio
Ronen Kfir wrote at Sun, 13 Jul 2003 19:29:27 +0300: I hold the visual studio .net professional CD. How do I install perl on it? Installed the windows compenents cd. Now I can see a setup page with checkboxes I have to choose from. Things like: Path Languege tools Etc. docomuntaation What have you tried to find out about .NET and Perl in combination? Perl is completely independent of .NET. If you want to install Perl, go to e.g. www.activestate.com and download their windows binary. What to choose, what not. In every case, you don't need anything of Microsoft to install Perl. You only need Perl. (With a C-Compiler, you can compile it from source code) How to continue after? Don't know, what do you want to do with Perl? Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to get a file
Vemulakonda Uday Bhaskar wrote at Fri, 11 Jul 2003 08:44:16 +: my $SFTP=Net::SSH::Perl-new(xxx.xxx.xxx.xxx) or die Cant connect; $sftp-login(xyz,abc); the above code is working fine. How do you know that the code is working fine? I don't know the Net::SSH::Perl module very well, but I could imagine that e.g. the following way would be more explicating: $sftp-login(xyz,abc) or die ...; Bu what is tehe command to get or put a file the command $sftp-get(filenamne) is showing a error. What an error? please help me What have you tried to help yourself? We can't help you without a good description what fails and what you tried to do to fix the problem. The latter is the most important, as you have posted several similar messages to this mailing list with only little efforts from time to time. (If I get the impression, that the help I'm trying to give here isn't worth the time, I'll stop answering) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question on For loop usage in Perl
Hari Krishnaan wrote at Thu, 10 Jul 2003 14:03:32 -0700: I was using a for loop in the following manner in one of my perl programs. for($j=31, $n=$initial;$j=0,$n=$final;$j--,$n++) { # Executing statements here } } 1) Is it legal in perl to use the for loop as mentioned above ? Yes (taking care of what Jenda already told), but it is not very Perlish. An independent reader (might be yourself in a year) can't understand on the first glance what the purpose of that loop is. I suggest that you want to run $n over $initial..$start, but at most 32 times. A, IMHO more readable solution might be: { my $loops = 0; foreach my $n ($initial .. $final) { last if ++$loops 32; # ... your stuff } } or perhaps shorter and also good readable: foreach my $n ( ($initial .. $final)[0 .. 31] ) { # ... your stuff } But of course, that's also a question of personal style :-) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Net::NNTP List does not work
Gene Mat wrote at Mon, 07 Jul 2003 23:18:38 +: I am trying to call the list function using NET::NNTP. use Net::NNTP; use strict; use warnings; would have told you where and why the error is. $nntp = Net::NNTP-new(nntp.perl.org,Debug,10); ($narticles,$first,$last,$GROUP)=$nntp-group(perl.beginners); $nnpt-list; ^^ $nntp-quit; All the other NNTP functions work fine group, date, xover, etc. However, when I want to get all the Newsgroup using either the list, active, or newsgroup functions. I get the following error. Can't call method list on an undefined value at ./getnntp.pl line 13. Any suggestions? Let Perl help you where it can, don't let a human make the work of a machine. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: CR at end of line - how do I parse this?
Christopher Fuchs wrote at Tue, 08 Jul 2003 14:29:50 -0700: I have a perl script on UNIX which works properly for an ASCII input data file which is in the form of: record 1 line 1 record 1 line 2 record 1 line 3^M record 2 line 1 etc The record delimiter is ^M (which is sometimes refered to as CR or \r). When run on a Windows box, the ^M is stripped away and as a result the program fails. I've tried all combinations of character strings for $/ without sucess. How do I get Perl/Windows to keep the ^M so I can parse this? binmode is your friend. Please read perldoc -f binmode Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: $! and $@
Jdavis wrote at Tue, 08 Jul 2003 14:39:17 -0600: I think these catch errors somehow... $! and $@ could someone explain this. Perl can explain it to you, just read: perldoc perlvar Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: newbie needs help
Dakenah Johnson wrote at Mon, 07 Jul 2003 10:11:37 +: I am writing a script that uses backquotes and the ps-ef command to print the UID and command for all currently running processes. You can also use a module instead of reinventing the wheel :-) Have a look to the CPAN module Proc::ProcessTable, e.g.: use Proc::ProcessTable; my $processes = Proc::ProcessTable-new; foreach (@{ $processes-table }) { printf Owner: %s, Command: %s\n, $_-uid, $_-cmndline; } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Stat() - Getting one element
Paul Kraus wrote at Mon, 07 Jul 2003 09:27:15 -0400: What's an easy way to grab just one element out of a function that returns a list. For instance if I was to stat a file and all I wanted was the $atime or if I just wanted the three timestamps atime mtime and ctime. Thanks. A completely different way that works in the special case of stat, would be my ($atime, $mtime, $ctime) = (-A $file, -M _, -C _); That also only calls once the stat function, but is a bit more intuitiv, as indexing them with [8,9,10] from the stat returning list. Read perldoc perlvar for details. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl SFTP help
Vemulakonda Uday Bhaskar wrote at Mon, 07 Jul 2003 13:21:53 +: use strict; use warnings; #!usr/bin/perl The usual ordering is to have that line as first line, followed by use strict; use warnings in the next lines. use Net::SFTP: my $sftp=Net::sftp-new(xxx.xxx.xxx.xxx); [the last line] That should be still uppercase. You might also need perhaps some arguments like the username or the password. this the is only code the error is coming in Line 37 There are only 6 lines in the code you've shown to us. What is the exact (Copy+Paste it) error message given to you? Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: formatting a number
Robert Citek wrote at Thu, 03 Jul 2003 18:48:02 -0500: I want to format a number so that it has commas as a separator. Here's the code I came up with: my $num=12345678; print scalar reverse( join(,, grep( /./ ,split (/(...)/,reverse($num), \n; This works but was wondering if anyone might suggest a better method. In addition to the FAQ, you can use the CPAN-Module Number::Format. use Number::Format; my $num = 12345678; my $f = Number::Format-new(-thousands_sep = ',', -decimal_point = '.'); print $f-format_number($num),\n; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Newlines, control characters, etc
Joshua Scott wrote at Wed, 02 Jul 2003 21:25:34 -0400: I'm trying to copy data from one database field to another. The problem is that the field contains various newline and other types of control characters. Whenever the script runs, it processes those as perl code instead of data like I'd like it to. How can I prevent it from doing this? Here is an example of what is happening. $variable = Some data\nSome more data\n\nBlah Blah This variable was populated from an SQL table. I'm trying to create a valid SQL scripts file so I do the following. print FILE INSERT into table (field) VALUES ('$variable'); The file gets created just fine, but when I view the file it looks like this: INSERT into table (field) VALUES ('Some Data Some more data Blah Blah If the string ends with a ' it is a full valid SQL script. Basically, I'd like it to look exactly as it is stored in the variable...which would be like this: INSERT into table (field) VALUES ('Some data\nSome more data\n\nBlah Blah; What do I need to do? You can do something like $variable =~ s/\n/\\n/gs; To say the truth, I would be more scared of e.g. ' contained in the string. Such stuff, I would prefer to quote with the DBI::quote method. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: noch ein kleines problem mit meinem script
Azubi Cai wrote at Thu, 03 Jul 2003 09:53:57 +0200: Das sieht jetzt so aus: #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use CGI; $cgi = new CGI; my $params = Vars; my %Formular = %params; ^ my %Formular = %$params; ^^ open PLATZ, dokument.rtf or die Error: $!; open PLATZ_TMP, dokument.rtf.tmp or die Error: $!; [...] Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: -w vs. use warnings
Charles K. Clarkson wrote at Wed, 02 Jul 2003 13:43:26 -0500: Read 'perlexwarn' in the perl documentation ^ Better to read perldoc perllexwarn ^^ for a complete discussion. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How to check Array Uniqueness without Modul Array::unique
B. Fongo wrote at Mon, 30 Jun 2003 23:46:19 +0200: Is there any other way to check array uniqueness except the Module Array::Unique? I'm having problems in installing these two Modules: Array::Unique and Tie. So I'm thinking of another way to check array for replicates. I help will be appreciate. Thanks a lot! You can also hardcode it e.g. { my %seen; if (grep {$seen{$_}} @array) { # at least one element is twice } else { # unique } } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: password encrytion perl help
Vemulakonda Uday Bhaskar wrote at Tue, 01 Jul 2003 09:11:00 +: my code looks like this: #!/usr/bin/perl Missing use strict; use warnings; $ftp=Net::FTP-new(xxx.xxx.xxx.xxx) else die not connected; or $u=STDIN; CHOMP $u; ^ chomp $p=STDIN; CHOMP $p; $ftp-login($u,$p) or die login failed; the code is working fine I doubt it. but the problem is when it asks password i need to give it , and so is visible to all. Is there any method so that the typed password can be typed secures so that it would get displayed as '*'s or some thing of that sort. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question about filehandles
Azubi Cai wrote at Tue, 01 Jul 2003 16:40:23 +0200: I need to substitute a string in a .rtf file with a string from an HTML form. I thought about using placeholders in the .rtf document and then searching and overwriting them with the data from the HTML form. I tried it out with that code: #!/usr/bin/perl -w open PASSWD, test.rtf or die nichts gefunden ($!) ; while (PASSWD) { chomp; if (/welt/) { s/welt/mars/; } } Your program open a file, read it line by line into a variable, chomp that variable and substitute something of that variable. But a variable per se, don't change the world. In general you will need another outputfile to write to and finally you simply move the new file to the old one. That would look like: #!/usr/bin/perl use strict; use warnings; open PASSWD, test.rtf or die Error: $!; open PASSWD_TMP, test.rtf.tmp or die Error: $!; while (PASSWD) { # chomping doesn't make a lot of sense here, # as we won't change the newline s/welt/mars/; # the if condition isn't necessary and is no # optimization print PASSWD_TMP; } rename test.rtf.tmp, test.rtf; Of course that program still has the known problems when using temporary files, but it illustrates the main principle. there aren't any warn messages from the compiler, but the string hallo welt hasn't changed into hallo mars. But whats' wrong? Or is it a problem with the .rtf format? Perl would not be Perl, if it wouldn't make a simple problem simple. You can replace the whole above program by a simple one liner: perl -pi -e 's/welt/mars/'; (read perldoc perlrun to understand what -pi and -e does) Greetings, Janek PS: Might be that you want to switch on also the g-modifier: s/welt/mars/g as without it, you will only change the first welt of every line to mars. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regex question
Jeff 'Japhy' Pinyan wrote at Tue, 01 Jul 2003 12:39:37 -0400: On Jul 1, [EMAIL PROTECTED] said: \.[^(gz|html)]$ this regex should match all files (lines) NOT ending with gz or html. or else use a negative look-ahead: if ($filename =~ /\.(?!gz|html)[^.]*$/) { # (?!...) means is not followed by } That regexp does not match only for files ending on .gz or .html, but also for files ending on .gzsz or .htmlx or similar. I would prefer to write it as /\.(?!gz$|html$)/ or /\.(?!(gz|html)$)/ Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help needed
Vemulakonda Uday Bhaskar wrote at Mon, 30 Jun 2003 09:37:31 +: but some error is coming from where do i download Net::SCP. is this code ok http://search.cpan.org Greetings, Janek PS: Don't post your messages more than one times. Otherwise you could get plonked by one or others. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Count Function?
Nelson Ray wrote at Thu, 26 Jun 2003 19:25:37 -0700: Does anyone know of any sort of a function or method in perl that returns the number of times a search string exists in a scalar. Say, how many a's are there in this sentence? I am able to write it myself, but I was wondering if Perl had an inherent function for cleaner operation. I tried looking through the list of functions at www.perldoc.com without success. Thanks a lot for any help. perldoc -q How can I count the number of occurrences of a substring Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: MD5 module
Mario Kulka wrote at Wed, 25 Jun 2003 19:36:45 +: Few days ago I sent a message about uploading modules but I just realized I wasn't subscribed to the list. I just re-subscribed but I missed the replys; is there a way to view the last messages posted to the list by date or something? or could someone just copy the reply to : How to install MD5 module to my hosting server and re-send it to me? An alternative way to the web access might be to use it from a newsreader. The appropriate nntp host is: nntp.perl.org (Port 119 of course) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Weekly list FAQ posting
case wrote at Tue, 24 Jun 2003 15:17:48 +: 2.9 Other tips before posting to the list * Check the FAQs first once * Don't send questions asking ... will this work?. Try it first, then report errors and ask the list why it *didn't* work. A good answer to will this work?, is What happened when you tried it?. * If your email begins with I know this isn't the right place to ask this, but..., don't send it to this list :) If you know it doesn't belong, send it to where it does. * Check the FAQs first twice * Look at the archives, (http://archive.develooper.com/[EMAIL PROTECTED]/) to see if your question has already been answered on the list. * Have meaningful Subjects. Subject lines like Help!, and This isn't working! may be skipped by many people, and you may not get all the great help you want. Try to make your subject lines meaningful. For example, sprintf() trouble, or Confused about formats. :-) Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help:Perl ssh file tranfer
Vemulakonda Uday Bhaskar wrote at Thu, 26 Jun 2003 10:14:22 +: please help me with the code which does the following : Where is the code? transfer of files from one system through another system which are both working on linux through ssh as iam in need of it urgently, exepecting a working codee What do you pay for? However, that's also not a job list - perl.jobs is one, Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Weekly list FAQ posting
Jenda Krynicky wrote at Thu, 26 Jun 2003 14:05:14 +0200: case wrote at Tue, 24 Jun 2003 15:17:48 +: 2.9 Other tips before posting to the list * Check the FAQs first once * Don't send questions asking ... will this work?. Try it first, then report errors and ask the list why it *didn't* work. A good answer to will this work?, is What happened when you tried it?. * If your email begins with I know this isn't the right place to ask this, but..., don't send it to this list :) If you know it doesn't belong, send it to where it does. * Check the FAQs first twice ... I agree twice is not enough. Yep, either once or following a german idiom, all good things are three ones! Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Please explain warnings error
Motherofperl wrote at Thu, 26 Jun 2003 08:35:05 -0400: I'm getting this warning: Possible unintended interpolation of @pkg::array1 in string What does it mean and how do I fix it? Let Perl explain it to you, include not only strict and warnings, also use diagnostics; If you still don't know what does it mean and how you can fix it, ask us again, but please also add some code. (It's hard to explain how to fix something without seeing that thing) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: help - perl ssh
Vemulakonda Uday Bhaskar wrote at Thu, 26 Jun 2003 12:41:16 +: i have wriiten a code for file tranfer between linux systems so i used Net::SCP qw(scp iscp). i downloaded it from the site http://serach.cpan.org/author/IVAN but after gunzip and tar -xvf.. when i gave the command as said in README file perl Makefile.pl it is giving error saying that cannot locate NET ncp/[EMAIL PROTECTED] please help me on how tosolve the problem and any other site where from i can download scp modules I'm not sure about the error message (better to copy+paste the complete error message than only one line), but perhaps you'll need also some other modules. Net::NCP needs also Net::SSH String::ShellQuote IO::Handle Only the last one is usually installed. I couldn't detect something special in it's Makefile.PL, so perhaps that's really the problem. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Matching
Sitha Nhok wrote at Thu, 26 Jun 2003 12:47:25 -0400: Is there anyway to match a string in a 2-dimensional array only at one index? For example, say I have this 2-d array: @AoA = ( [ABC, BCD], [CDE, DEF], [EFG, FGH], ); Then I wanted to see if CD exist, but only in column index 1 ($AoA[$row][1]). Is there a way to do this w/o using a for loop within a for loop? Thanks. [untested] if (grep /CD/, map {$_-[1]} @AoA) { ... } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Help needed on XML Files
Sherwin Remo wrote at Tue, 24 Jun 2003 06:56:40 +0800: I would like to write a script that would check the correct syntax of an XML file. Need to check if the file is XML compliant. Is there a module that I can use to do this? Thanks! There are a lot of XML modules on CPAN: http://search.cpan.org/search?query?XMLmode=module e.g. also XML::Checker Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perl reg exp problem
Robin Garbutt wrote at Mon, 23 Jun 2003 11:40:47 +0100: I have a string that is a random sequence like the following:- ACGTCGTCGTCACACACACGCGTCTCTATACGCG I want to be able to parse the string, picking out any TATA sequences, colour them in red and make a not of where ther lie in the sequence. Is this possible with perl? Yes, but you have to explain in what matter you want to colorize. As output in a terminal window, as html/xml, as a picture, as a word document ... . If you would have in a pseudo-xml with the tag red.../red, you would perhaps do it as: $string =~ s/(TATA)/red$1/red/g; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: installing modules
Mario Kulka wrote at Mon, 23 Jun 2003 03:40:03 +: Could anyone give me step by tep instructions on how to install a perl module (MD5) on my host server. How come they don't have it installed? Isn't popular enough? BTW, the MD5 module is deprecated. It is recommended to install Digest::MD5 instead. The simplest way to install it is to type perl -MCPAN -e 'install Digest::MD5' The other, more classical way to install is to get the package from cpan (http://search.cpan.org/CPAN/authors/id/G/GA/GAAS/Digest-MD5-2.24.tar.gz) to unpack it and then to follow the normal way perl Makefile.PL make make test make install (last as root) Please read also perldoc perlmodinstall to get a more detailed explication. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Why
Scott_g wrote at Sun, 22 Jun 2003 15:21:24 -0500: Hello. I am new to Perl. I used to program in C years ago (not C++ # etc) I have the simplest question. I am running active state perl 5 on Win XP. I'm using OpenPERL Ide 1.0 #!k:/perl/bin/perl.exe # # Camel-Learning Perl # Exercise 2-4 # Input a b from Console STDIN # Then multiply print them # print Enter an integer: ,$a=STDIN;# This don't work Perl interpretes this as print( Enter an integer: , $a=STDIN ); So it can executes print only when both arguments are evaluated first, forcing you to enter $a before you see the prompt. # print Enter an integer: \n;# Neither does this $a=STDIN;# ... This program excerpt above is driving me crazy! I can NOT get the PROMPT to appear BEFORE the program waits for input. I have tried several different ways to do this. No matter what I do, the screen stays blank, until I enter a value, THEN the prompt is printed! This works for me, but when I get into a larger program, the USER is going to have to read the PROMPT BEFORE they know what to type in! Try instead the explicit print(Enter an integer: ),$a=STDIN; allthough I still would prefer in most cases to write the semicolon instead of the comma (but of course in some cases it's very useful like print(...),$x=STDIN unless defined($x); ) Greetings, Janek PS: $a is a bad name for a variable as it is a global variable used for sortings. (Read perldoc perlvar for details). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: format
Ataualpa Albert Carmo Braga wrote at Fri, 20 Jun 2003 02:28:11 -0300: I did a small script with perl and I'd like to format the output: C -3.7975162.078833-0.795507 C 4.0463240.905644-0.106181 C 4.0372860.8874121.283492 C -3.7633952.0493061.974280 C 3.5107383.2438591.300844 C 3.5326323.241100-0.087005 S 4.426205-0.568871 -1.005668 O -4.671286-0.193843 -2.360360 C 3.2476724.5126252.076377 [...] like this: C -3.7975162.078833 -0.795507 C 4.0463240.905644 -0.106181 C 4.0372860.8874121.283492 C -3.7633952.0493061.974280 C 3.5107383.2438591.300844 C 3.5326323.241100 -0.087005 S 4.426205 -0.568871 -1.005668 O -4.671286 -0.193843 -2.360360 C 3.2476724.5126252.076377 Is it possible? printf and sprintf are youre friends (perldoc -f sprintf). Look e.g. to: Something like this snippet should give you the idea: while (DATA) { my @col = split; printf %-1s\t% 1.6f\t% 1.6f\t% 1.6f\n, @col; } __DATA__ C -3.7975162.078833-0.795507 C 4.0463240.905644-0.106181 C 4.0372860.8874121.283492 C -3.7633952.0493061.974280 C 3.5107383.2438591.300844 C 3.5326323.241100-0.087005 S 4.426205-0.568871 -1.005668 O -4.671286-0.193843 -2.360360 C 3.2476724.5126252.076377 Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Problem with making the Perl Module Date::Calc
Anand Babu wrote at Fri, 20 Jun 2003 12:32:22 -0700: Warning: prerequisite Bit::Vector failed to load: Can't locate Bit/Vector.pm in Seeing this warning I would recommend you also to install the module Bit::Vector Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: perldoc - html format ?
Jeff Westman wrote at Fri, 20 Jun 2003 11:33:59 -0700: Is it possible to reformat a perldoc in HTML format? I don't see this as an option to 'perldoc'. From perldoc perldoc -o output-formatname This specifies that you want Perldoc to try using a Pod-formatting class for the output format that you specify. For example: -oman. This is actually just a wrapper around the -M switch; using -oformatname just looks for a loadable class by adding that format name (with different capitalizations) to the end of different classname prefixes. For example, -oLaTeX currently tries all of the following classes: Pod::Perldoc::ToLaTeX Pod::Perldoc::Tolatex Pod::Perldoc::ToLatex Pod::Perldoc::ToLATEX Pod::Simple::LaTeX Pod::Simple::latex Pod::Simple::Latex Pod::Simple::LATEX Pod::LaTeX Pod::latex Pod::Latex Pod::LATEX. So, if you want to see it in HTML output, just try something like perldoc -oHMTL perldoc Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: regexp
Jaschar Otto wrote at Wed, 11 Jun 2003 11:53:11 +0200: i've got a problem with regexp, i have a multiline string like this is a multi line string and i want to do a regexp that replaces everything that is NOT a,b,c or d with \s, except \n of course. \s is not one character, it stands usually for a whole character class! Do you mean an empty string () or just a blank ( ) instead? i got something like $string =~ s/![abcd]//g; character class negation works with [^...], in your case it would be $string =~ s/[^abcd]//g; but that doesn't work, maybe because it recognizes ! not as negation but as character... so how to do it ? Please read also perldoc perlre for details. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: mathing only one type of characters
Pedro Antonio Reche wrote at Wed, 11 Jun 2003 13:38:18 -0500: I would like to match a string if it has only cero or more of a defined set of characters. For example: if GACT are the characters, then GACTNGACT ## This string should not be matched because it has the extra character N GACCC ## This could be matched; Any help to solve this problem will be greatly appreciated. Just another (from my point of view direct) view is $string =~ /^[GACT]*$/; The anchor stands for the beginning of the string, [GACT]* stands for zero or more of the defined characters $ stands for the end of the string. If you want to know more about regexps, read perldoc perlre Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Spliting comma delimited data
Rob Anderson wrote at Mon, 09 Jun 2003 16:08:54 +0100: I have the following code, which I intend to use to save/restore an array to/from a text file with. As I'm using a comma to delilmit the data I'm escaping commas on the way out, an unescaping on the way in. This means that when I split the string into an array, I need to make sure I DON'T split on escaped commas, hence the /[^\\],/ regex in my split. But my problem is that this split strips the last character off all but the last element in the array. Is there some way to exclude the [^\\] part from being matched, err or something, help. My code... [...] That's already invented. The CPAN modules Text::CSV Text::CSV_XS can solve your problems (and take also care for commas in quotes) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How can I find the module version?
Rick Ressegger wrote at Tue, 10 Jun 2003 09:32:53 -0400: If I want to know what version of a module is already installed on a system, how can I disclose this? A simple way that works often is perl -MModule::Name -e 'print $Module::Name::VERSION' Another way would be e.g. to use the CPAN module Module::Info Can multiple versions of a module exist in a library or does one get superceded by another that is installed later? You can have as many different module versions on a system as you want. The first module found in the paths, specified by @INC is choosen. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Why Can't locate auto/Heap/add.al?
Ying Liu wrote at Thu, 05 Jun 2003 20:20:02 -0500: I finally install the Heap module. But I run the example of the CPAN: foreach $i ( 1..100 ) { $elem = NumElem($i); $heap-add($elem); } } It told me: Can't locate auto/Heap/add.al in @INC I search this directory but didn't find the add.al, is it caused by the wrong installing or something else? There seems to be two bugs in the documentation. First, you have to use a specific Heap-Class for the constructor (e.g. Heap::Fibonacci), Second, there is no extract_maximum but an extract_minimum function in the heap module. Together, the following snippet runs: use Heap::Fibonacci; my $heap = Heap::Fibonacci-new; my $elem; use Heap::Elem::Num(NumElem); foreach $i ( 1..100 ) { $elem = NumElem( $i ); $heap-add( $elem ); } while( defined( $elem = $heap-extract_minimum ) ) { print Smallest is , $elem-val, \n; } I'd rather suggest to contact the author of this module, as it seems really to be a bug that has to be fixed. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: typing files quickly
Harry Putnam wrote at Sat, 07 Jun 2003 02:18:32 -0700: So you can use: if (-f $file) { : # process file } elsif (-d $file) { : # process directory } } Well, yes of course I can run each filename thru all those tests, but that seems kind of like a lot of huffing and puffing. I wondered if there isn't something that just spits it out. perl `stat' does do that very thing in element[2] ($mode) but extracting `type' from that number looks hideously complicated. Maybe running all possible tests is quicker and easier after all. It would really come down to just these: -f -d -l -b -c -p -S But all that info is available in @elems = (stat fname); Unix `stat' actually spits it out in plain english, what type it is. (at least gnu `stat' does) If you write instead if (-f $file) { # } elsif (-d _) { # ^ } Then there is no extra stat call. The underscore _ holds the results of the last stat call (implicitly called by the -f operator), so no unnecessary work needs to be done. So you gain all stat informations in equivalent access time, but with a much improvement in readability. (A typical statement of my programs look e.g. like if (-e $file -f _ -M 3) { ... # process existing files, older than 3 days } ) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Am i taking the right approach (i have to learn to code this!)
Angel Gabriel wrote at Wed, 04 Jun 2003 17:44:28 +0100: As some of you know, I'm attempting to create an internal system to automate some stuff. This is how I plan to do this... Year, that's exactly the way, you should start. It will be possible to translate your pseudo code nearly 1:1 to Perlish :-) #!/usr/local/bin/perl include email reading modules There are a lot of them on CPAN, depending what email system you are using (mbox, pop, imap, whatever windows uses, ...) and what kind of interface you prefer. include grep modules (if exists, not found any yet) I'm not sure what you mean with that. grep is a perl and a shell command with similar, but not exact the same behaviour. Perhaps it's better, when you clarify that point a bit better. include MySQL writing modules Erm, the normal way is to use the generic database indepentend module DBI and a driver for MySQL, should be DBD::mysql (both on CPAN). The documentation for them is very large and should already help you. (If you plan simple database things, you might also have a look to the CPAN module DBIx::Simple ) read email from pop mail box Simple with the right module (Net::POP3 could be one). take email addresses from header or attachment, (maybe both) Taking from header is simple (I would suggest Mail::Header), taking from attachment is a bit more difficult. A bit more clarification could be helpful. add to MySql database Easy with the DBI and DBD::mysql (alltough it's perhaps more an INSERT) forward email to another pop account Also easy with the right module, I suggest e.g. Mail::Mailer (allthough, there are many other ones) delete email Done by Net::POP3 e.g. end i am hopping that all the steps that i hope to do, can actually be achieved in perl. if anyone knows of any gotchas that i might face, can someone say so? Good luck, you're on the right way to (camel) heaven. If you get problems in the specific implementation, this group will be there to help you. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Perl - Web Development
Paul Kraus wrote at Wed, 04 Jun 2003 09:49:10 -0400: This may be asking for biased opinions but here goes anyways... Is perl still a good choice for the web. For instance I need to setup a couple sites that are going to be running on IIS. Is perl still a good choice for speed ect... In addition to the others, Perl's greatest benifitit is perhaps the choice for speed of the (expensive) programmers. Everything that can be done with Perl, can also be done with C, C#, VB.net, ... (and if you are good than also quicker), but a good Perl programmer will be much quicker than good C, good C#, good VB.net, ... programmers. (The only exception, I see, is PHP, but that's not such powerful than Perl is - but powerful enough for web applications) If you are already familiar with Perl but not with PHP, you should choose Perl, IMHO, reducing the extra work. Greetings, Janek PS: And for big, specialised applications (e.g. shopping websites), there are expensive, but convenient tools (like the one of Intershop). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Regular expressions
Saurabh Singhvi wrote at Tue, 03 Jun 2003 22:38:47 -0700: well i was trying to understand the regular expressions in perl when i came across STDIN i tried my best but i havent been able to get the slightest idea on how the input thing works. The editor i use is DzSoft. And it shows something like get and something else below like script something with blank space. What have you tried so far (code)? What's your exact question? Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sorry about how simple this question is
Klinsitik Reckon wrote at Tue, 03 Jun 2003 19:16:01 -0700: I am just starting to learn with perl. What software, books, or web sites would be helpful to learning the VERY basics of this new language. I do have some knowledge ofprogramming(in HTML, JavaScript, and C). Not much though. If you can help me please reply, Read also, perldoc -q book Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Installing Heap Module
Ying Liu wrote at Tue, 03 Jun 2003 15:45:32 -0500: [...] After I changed all those folders, I can install the Heap module succssfully. But when I use it by: use Heap /mz/hd/liuyi/local/Heap-0.50 It said: Can't locate Heap/Fibonacci.pm in @INC (@INC contains: /usr/perl5/5.00503/sun4-solaris /usr/perl5/5.00503 /usr/perl5/site_perl/5.005/sun4-solaris /usr/perl5/site_perl/5.005 .) at Heap.pm line 24. BEGIN failed--compilation aborted at Heap.pm line 24. BEGIN failed--compilation aborted at t.pl line 3. So, how to change the @INC or let Perl know the position? use lib '/mz/hd/liuyi/local/Heap-0.50'; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: arrays and hashes
John W. Krahn wrote at Mon, 02 Jun 2003 14:44:41 -0700: You should probably use an array to keep the correct order and a hash to keep the count: Or to use Tie::IxHash. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Installing Heap Module
Ying Liu wrote at Fri, 30 May 2003 10:48:06 -0500: When I install Heap module, I don't have the superuser permission and set the install location by run: %perl Makefile.PL PREFIX=/mz/hd/liuyi/local/Heap-0.50 %make %make test The above three commands run OK, but after I run '%make install', it told me: Warning: You do not have permissions to install into /usr/perl5/site_perl/5.005/sun4-solaris at /usr/perl5/5.00503/ExtUtils/Install.pm line 61. mkdir /usr/perl5/5.00503/man: Permission denied at /usr/perl5/5.00503/ExtUtils/Install.pm line 57 make: *** [pure_site_install] Error 2 Is there someone can help me? What's the matter at the last step? Your admin. You need usually root privileges to write to that directories. Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: DBI:mysql
Jaws wrote at Thu, 03 Apr 2003 14:47:02 +0800: I tried using the following: my $sth = $dbh-prepare(q{INSERT INTO MYTABLE (USERNAME,PASSWORD) VALUES (?, ?) }) or die $dbh-errstr; $sth-execute($username,PASSWORD('$pass')) or die $dbh-errstr; $dbh-disconnect; but i got this error: Undefined subroutine main::PASSWORD called at ./adduser.pl line 30, STDIN line 4. Any suggestions? Well, I'm not an expert in this topic, but have you tried my $sth = $dbh-prepare(q{INSERT INTO MYTABLE (USERNAME,PASSWORD) VALUES (?, PASSWORD(?))}); $sth-execute($username, $pass) or die $dbh-errstr; Best Wishes, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: $|
Rob Dixon wrote at Sat, 29 Mar 2003 12:59:22 +: $| If set to nonzero, forces a flush right away and [ ... ] I'll throw in my usual thing here: that it's better to use use IO::Handle;# a standard module autoflush STDOUT; Looks really good :-) use IO::Handle; autoflush STDOUT; autoflush STDERR; print STDERR STDERR\n; print STDOUT STDOUT\n; so that the output you see is in the order it happens. Without the autoflush calls ( or even with just $| = 1 ) the above program will output STDOUT STDERR The following snippet: #!/usr/bin/perl $| = 1; print STDERR STDERR\n; print STDOUT STDOUT\n; $| = 0; print STDERR STDERR\n; print STDOUT STDOUT\n; has the output STDERR STDOUT STDERR STDOUT and not STDOUT STDERR ... Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: $|
Dan wrote at Sat, 29 Mar 2003 10:20:33 +: Just a quick question, what is the meaning of this $| and what is it supposed to do? From perldoc perlvar $| If set to nonzero, forces a flush right away and after every write or print on the currently selected output channel. Default is 0 (regardless of whether the channel is really buffered by the system or not; $| tells you only whether you've asked Perl explicitly to flush after each write). STDOUT will typically be line buffered if output is to the terminal and block buffered otherwise. Setting this variable is useful primarily when you are outputting to a pipe or socket, such as when you are running a Perl program under rsh and want to see the output as it's happening. This has no effect on input buffering. See getc in perlfunc for that. (Mnemonic: when you want your pipes to be piping hot.) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Variable scoping, static variable
Rob Anderson wrote at Fri, 28 Mar 2003 14:45:07 +: -- module sub routine sub test { my $param = shift; my $cache_key = param=$param; if (exists $cache{$cache_key}) { return $cache{$cache_key}; } sleep 1; $cache{$cache_key} = $param . done; # save the value } My problem with this is that I can't use strict, because I'm not declaring %cache. If I do use strict, I'm forced to declare %cache, and when the sub ends, the hash goes out of scope. So, my question is, can I create a 'static' hash for this fuctions that'll work with warnings and strict? I know that there are modules for caching functions, but I don't have much control of the environment and would rather not install extra modules. Try a closure: { my %cache; sub test { my $param = shift; my $cache_key = param=$param; if (exists $cache{$cache_key}) { return $cache{$cache_key}; } sleep 1; $cache{$cache_key} = $param . done; # save the value } } Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Enumerating available modules
Steve Gilbert wrote at Fri, 28 Mar 2003 09:28:17 -0800: Does anyone know of a way to enumerate all the available modules on a system? Have a look to the CPAN module ExtUtils::Installed Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Split Problem
Jimstone7 wrote at Thu, 27 Mar 2003 06:39:25 -0500: $data = David (man from uncle); $data = John Doe (The boy down the hall); What I want to do is split $data into two string variables, one holding the $name, and the other holding all the $info that is within the parens. How would I do this? Thanks for any help. I would use a regexp: my ($name, $info) = $data =~ /(.*?)\w+\((.*)\)/; Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Split Problem
Stefan Lidman wrote at Thu, 27 Mar 2003 13:55:27 +0100: Janek Schleicher wrote: I would use a regexp: my ($name, $info) = $data =~ /(.*?)\w+\((.*)\)/; I guess you ment: my ($name, $info) = $data =~ /(.*?)\s*\((.*)\)/; Yep. Cheerio, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Split Problem
Rob Dixon wrote at Thu, 27 Mar 2003 12:51:46 +: Janek Schleicher wrote: $data = David (man from uncle); $data = John Doe (The boy down the hall); What I want to do is split $data into two string variables, one holding the $name, and the other holding all the $info that is within the parens. How would I do this? Thanks for any help. I would use a regexp: my ($name, $info) = $data =~ /(.*?)\w+\((.*)\)/; Hi Janek. I'm afraid your regex is wrong! It does the following: Yep, it was a typo and untested. capture zero or more (as few as possible) of any character !! match one or more 'word' characters followed by an open parenthesis capture zero or more (as many as possible) of any character match a close parenthesis Replace the \w+ with a \s* like of Stefan suggested, an everything works fine :-) The main advantage of a regexp solution against a split solution is that it will also work with something like $data = Janek Schleicher (The (not yet) perfect regexp man :-)) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: how can I delete a line?
Adriano Allora wrote at Tue, 25 Mar 2003 15:39:14 -0800: hello, I need to delete single lines in a text (for example the 132nd, the 133rd and the 134th ones). How can I do it in a structure like: if $. = selected number line = As TMTWTDI, here's another one: while () { print if (1 .. 131) || (135 .. -1); } However, for such jobs, it's also often a good idea to use the Tie::File module, where you could use a splice to delete the lines, e.g. [untested] tie my @line, 'Tie::File', $filename or die ... ; splice @line, 131, 3; # Note that the 132nd line has index 131 Best Wishes, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Binary File Reading
Chrkôkîéánîkï wrote at Wed, 26 Mar 2003 12:34:15 -0300: I'm new in Perl, and I need to analyze a binary file, byte per byte. $/ = undef; open FILE, file.bin or die $!; binmode FILE; my $data = FILE; is that ok? how can I get one byte, the next, the next, etc? Thanks in advance!! You can either set $/ to a reference to a number defining in what length of chunks the files should be read: $/ = \1; while (my $char = FILE) { print $char, \n; } or use the read function of Perl, see perldoc -f read for details. Best Wishes, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Using Print -strange behavior
Jose Luis Martinez wrote at Sun, 23 Mar 2003 15:04:42 -0800: This is the code that I am trying to run #!/usr/bin/perl my $a=Hello World; print $a; Runs fine for me, allthough I wouldn't use $a as a variable. (It's already a global variable used e.g. in sortings, see perldoc perlvar for details) Greetings, Janek -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]