Re: Beta Testing a Robot
Casey West wrote: I'm beta-testing a robot that searches Google when new questions are posed to the beginners' lists. I have no idea if it will be useful. :-) I'm going to watch it closely and hope it is. I'll remove it if I find that it does a bad job. Casey West Hi Casey, I'm getting in on this sorta late, but here's my $0.02 worth: I don't mind getting the bot responses. I guess I may be in a minority on this subject though. One thing I do see is a fairly broad spectrum search that sometimes shoots pretty wide of the mark. There are a couple branches to this, in my view: 1. The search seems to respond to boilerplate with equal or greater weight than to the meat of the question. I se the same problem with the perldoc -q implementation on my computer. I've got some thoughts on approachesw to this, but I'll defer them to later, because they are pretty speculative. 2. There may be benefit to using a prioritized search pattern with the significant content of the search string. I have been working on an archive manager for my record of this list [actually a generalized mailbox archive manager, and here is the approach I took. I actually had three search options: Precise phrase [case-insensitive], all words, and any words. The current search pattern seem to be more of an all words search. It might help to narrow that down to demand matches on mutliple words. Within my all words serach, I also used a priority queue system for ordering response by significance. Here I scan the file keeping a count of total matches found, and ensuring that each word was matched at least once: Note that each entry in the hash pointed to by $found_in, and loaded by iterative calls to this routine has a 'count' element. input: $regexes--anonymous array of search strings $file_key--anonymous array of message sequences numbers $files--anonymous hash of filenames, keyed by the above $file_keys $found_in--anonympous hash to be loaded with filenames, keys, and counts sub seek_all_words_in_file { my ($regexes, $file_key, $files, $found_in) = @_; my $file = $files-{$file_key}; open IN, $file or die Could not open $file $!; my $matchcount = {}; $matchcount-{$_} = 0 foreach @$regexes; my $line; $line = IN until $line and $line eq \x0A; # This gets me past a header section of the file I'm scanning my $total_count; while (defined ($line = IN)) { foreach my $regex (@$regexes) { # get match counts per line of each regex if (my $line_match_count = () = $line =~ /$regex/gi) { $matchcount-{$regex} += $line_match_count; } } } my $matched_all = 1; for (@$regexes) { $matched_all = 0 if not $matchcount-{$_}; # filters if any words are missing } return if not $matched_all; my $count; $count += $matchcount-{$_} for @$regexes; $found_in-{$file_key}-{filename} = $file if not $found_in-{$file_key}; $found_in-{$file_key}-{count} = $count; } The calling function uses the above scanning routine thusly: ... while (my $file_key = shift @$file_keys) { seek_all_words_in_file($regexes, $file_key, $message_files, $found_in); } display_search_results($found_in, $search_dialog); ... handing it off to the following sub. Keep an eye on the hash pointed to by $best_bets, since that is the actual priority queue mechanism: sub display_search_results { my ($found_in, $search_dialog) = @_; our $message_viewer; our $message_list; my $best_bets = {}; foreach my $file_key (keys %$found_in) { my $file = $found_in-{$file_key}; my $line_count = $file-{count}; $best_bets-{$line_count} = [] if not $best_bets-{$line_count}; push @{$best_bets-{$line_count}}, $file_key; } $message_list-delete('all'); my $match_count = 0; foreach my $priority_level (sort {$b = $a} keys %$best_bets) { foreach my $file (sort {$b = $a} @{$best_bets-{$priority_level}}) { my $details = get_message_info($file); add_message_to_tree($file, $details, $message_list, $file) } } set_viewer_status('sort', 'none'); } Of course this still somewhat lacks subtlety. For one thing there is no weighting for the balance of search words in the file being searched. It might be better to give extra points for files that had all words in roughly equal quantity. Between precise phrase and all words is also another standard, that I hadn't really tried to explore. That would be words in order'. Something like this might be best with the record separator set to a period, so that it would scan text on a sentence-by-sentence basis, looking for all words in the same order as the search phrase, even if intermingled with other text. Unlike the above, I haven't built or tested this but a general algorithm for the regex might be: my $regex = quotemeta shift @search_words; regex .= .*$word while my $word = quotemeta shift @search_words; Whcih should render a regex that will match any string
Re: Pattern matching
I went back to my books to refresh my memory on how to use references. Your suggestion help a lot, but the subroutine returns wrong values. I did some small modifications on the codes below , and tried it. It return perl-5.8.0-80.3.i386.rpm and samba-2.2.7-5.8.0.i386.rpm, which is wrong because: 1. The perl version available on the ftp server is higher. 2. The samba version already installed is higher than the one on the ftp server. my @remote_packages = qw(perl-5.8.0-88.3.i386.rpm samba-2.2.7-5.7.0.i386.rpm bob-5.3.2.4.1.rpm xml-2.5.2.1.rpm); my @installed_packages = qw(perl-5.8.0-80.3.i386.rpm samba-2.2.7-5.8.0.i386.rpm bob-5.3.2.4.1.rpm); # I expect perl-5.8.0-88.3.i386.rpm to be returned here. my $need_list = check_lists([EMAIL PROTECTED] , [EMAIL PROTECTED]); foreach my $pkg (@$need_list) { # $ftp_server-get($pkg) ; } # # sub check_lists { my ($src, $dst) = @_; #Making a quick pick hash my %src_hash = map { $_ = 1 } @$src; my @need_list; foreach my $key ( @$dst ) { push(@need_list, $key) unless(exists($src_hash{$key})); } # It should return only packages that are higher than those I've already installed. [EMAIL PROTECTED]; } # end of check_lists --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
DBD ERROR
Hi! With this piece of code foreach $gif (@files){ @gif_parts = split(/_/,$gif); print Inserting into id=$gif_parts[0], name=$gif: ; # Read file into scalar open(IN, $gif ) or die $!; binmode(IN); my $doc_len = read IN, $doc, $max_len; close(IN); print qq{$doc_len bytes\n}; my $tmp=STDIN; #just to make it one by one... # Insert document into the database. # Prepare the insert statement. #my $sth=$dbh-prepare(qq{INSERT INTO PELRER_TEST(id,name,data) VALUES (SEQ_PERLER_TEST.nextval,?,?) }); $sth=$dbh-prepare(qq{UPDATE dla15_download_content set web_sample_file1=? where id=?}); # Bind variables to columns. print $gif_parts[0]\n; $sth-bind_param(1, $doc, {ora_type = ORA_BLOB} ); $sth-bind_param(2, $gif_parts[0] ); # Insert/Update my $rv = $sth-execute(); } I get : DBD::Oracle::st execute failed: (DBD ERROR: Need bind_param(..., { ora_field=... }) attribute to identify table LOB field names) at dbi2.pl line 45, STDIN chunk 1. DBD::Oracle::st execute failed: (DBD ERROR: Need bind_param(..., { ora_field=... }) attribute to identify table LOB field names) at dbi2.pl line 45, STDIN chunk 1. Issuing rollback() for database handle being DESTROY'd without explicit disconnect(), STDIN chunk 1. Can anyone suggest? Ant. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl Advent Calendar
Mark Fowler has been doing a grand job of producing an annual Perl advent calendar. Each door has a different Perl module behind it. Take a look here: http://www.perladvent.org/2003/ Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Beta Testing a Robot
On Dec 4, 2003, at 8:41 PM, R. Joseph Newton wrote: Guay Jean-Sébastien wrote: ... Though it doesn't benefit those who didn't post the question (and answers seldom do, since people who can answer questions normally don't need the answers), I would not assume that at all. Programming is an extremely open-ended art and set of skills. I think the veterans on the list benefit as well as newbies from the discussions. Since there are always many approaches to take to any problem, we all gain fresh insigths from the interchange. [..] I'd underscore that a few more times. Think about the context of perl - it is internet glue - so there is stuff always rolling over the rollers from all sorts of directions, DBI, Unix, Cgi, Win32, insertYourModuleKultHere. So there is always more stuff to play with each time around. As an illustration I finally broke down and downloaded the POE and crawled through it, to see if it really would make me all warmUndtFuzzy... While it is intrinsically true that IF I happen to know an answer, then I don't need that one answered, but there may as R. Joseph points to it, a 'fresh insight' that comes from seeing N-ways to solve that 'one question'. While this overall point is very valid, it is taken out of context. By switching the word answers to fit the context, something such as automated tool to generate links to search results found in common locations then those answering don't need the answers, as presumably they know how to search google, cpan, perl.org, etc. (at least I hope, but then my house of cards has been shattered before ;-)) and they aren't looking for an answer per se. Which is possibly a better way to think of this list, nearly 50% of the answers provided are not an answer but where to find an answer, or how to interpret the answer provided by that location (often the perldoc). Which really gets back to Casey's original impetus and drieux's 'fix the root of the problem' post, which I intended to respond to but will now just do so here. I think it is a good idea and had started to work on something to that effect, where rather than posting the same answers to the same questions I would just post a link to a summary of the discussion that had previously taken place. Not unlike what drieux has done and proposed, but slightly different. drieux's content is excellent I think, but may go slightly too far by enriching the topic with additional code build out pieces, which if you have the time are worth it to read (and the OP will probably run into the problems that are extrapolated and covered all at once, if they could only see that they would but they may (probably?) won't), may get in the way of someone looking for a distilled IJustWantTheDamnAnswer listing ;-). Having said all of that I also know what resources are out there, FAQs, Cookbooks, etc. so who knows whether it would actually work. I do think the end object is different than what is available, tutorials, Perl FAQs (rather than real world problem FAQs, maybe?), straight cold documentation, automated First Response, so I may still have a stab at it, pending of course the new year ;-)... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: 64 bit Perl memory test...
NIPP, SCOTT V (SBCSI) wrote: Very interesting... Running this script it dies at the 800MB attempt. However, watching this process in top, memory usage is actually double the amount that is being tested. In top, the last memory amount prior to it dying is 1400MB. Could be that the data is atctually using only the first 32 bits for each 64 allocated. That would mean that it would take twice as much memory to store the same amount of data. Gotta get to work. I'll try to expand on this later. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Beta Testing a Robot
On Dec 5, 2003, at 6:58 AM, Wiggins d Anconia wrote: [..] may get in the way of someone looking for a distilled IJustWantTheDamnAnswer listing ;-). [..] Let's review the bidding a bit so far. A brief review of the last 45 days will get you to Jason's original Kvetch about not quite getting 'perldoc' - hence the desire to 'just ask a question'. As such Casey has implemented a solution for the just ask_the_perl_bot ... As some are starting to notice, there are those minor technical distinctions between 'syntax' and 'semantics' - that while it is reasonably easy to build a device that can parse out syntactical tokens and 're-use them' the issue of dealing with 'meanings', and with the implications of those 'meanings' get a bit messy. We just had one question today, where a part of the answer really was NOT about how to do the DBI foo, but about stepping back and getting a better feel for how 'basic perl' really works SO that the OP could step back into original set of Issues about DBI. So there is always going to be a bunch of problems associated with 'the meaning of meaningful' and when has one 'over stepped' 'the simple answer' trying to get at a 'root cause problem'. All writers face the risk of losing their audience. It's a bug in the basic 'semantical engine' - but for some reason primates keep avoiding fixing that!!! ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Frustrated newbie question
Help. I'm a frustrated newbie who wants to use Perl to make my life easier. The following simple task is only one small part of a program I'm trying to put together to automate some things I currently do manually. I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. I currently use a macro with a text editor to clean up the file into the one name per line format. I can do this very quickly in contrast to the the last two hours I've spent trying to figure out how to get Perl to do this very simple task. Arrggh ! To simply things, I just tried to take the following string and print it out one name per line. my $x = name1 name2 name3; I've tried various schemes using regex's and the ///s operator. Most of the time I get syntax errors and the few times I get anything to work, it's not what I want. I did get this array structure to work: my @names = qw(name1 name2 name3); print $names[0] \n; print $names[1] \n; print $names[2] \n; So I then spent time unsuccesfully trying to figure out how to get my string split into the array. I couldn't get that to work either. More Arrggh ! Anyway, any help at this point will be appreciated. I'm hoping that in the long run the time I spend learning Perl will pay off, which it will if I can automate some of the tasks I do manually (with the help of macros in a text editor). My next Perl task after I get my list of one name per line, is to sort the list and eliminate duplicate names. Thanks again for any help. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Frustrated newbie question
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, December 05, 2003 11:54 AM To: [EMAIL PROTECTED] Subject: Frustrated newbie question Help. I'm a frustrated newbie who wants to use Perl to make my life easier. The following simple task is only one small part of a program I'm trying to put together to automate some things I currently do manually. I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. snip I did get this array structure to work: my @names = qw(name1 name2 name3); print $names[0] \n; print $names[1] \n; print $names[2] \n; So I then spent time unsuccesfully trying to figure out how to get my string split into the array. I couldn't get that to work either. More Arrggh ! snip - I'm pretty much a newbie myself and don't understand qw as well as I need to yet but it seems as if you want to read up on the 'split' function. HTH, Chris. - - Chris Mortimore Information Services Graceland University mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: 64 bit Perl memory test...
R. Joseph Newton wrote: NIPP, SCOTT V (SBCSI) wrote: Very interesting... Running this script it dies at the 800MB attempt. However, watching this process in top, memory usage is actually double the amount that is being tested. In top, the last memory amount prior to it dying is 1400MB. Could be that the data is atctually using only the first 32 bits for each 64 allocated. That would mean that it would take twice as much memory to store the same amount of data. Gotta get to work. I'll try to expand on this later. another possible explanation is when your program is doing: allocate 100mb memory to $i undef $i allocate 200mb memory to $i undef $i allocate 300mb memory to $i undef $i ... allocate 800mb memory to $i undef $i ... at the end of your program, you are not really only using 800mb of memory. the 'undef $i' statment only tells Perl to free the memory $i is using if there is no other reference to it. it does NOT return the memory back to the os. which means all the memory allocated before the 800mb request are still held by Perl but again this does not neccessary mean Perl is holding 100mb + 200mb + 300mb + ... + 800mb memory though. for example, when your program is requesting 500mb of memory, Perl maybe able to find that by reusing the undef-ed 100mb + 400mb previous allocated so it doesn't have to ask the os for that. the behavior whether Perl will go ask the os for memory or reuse previous allocated is unpredictable and depends on many other factors at the time of the program is running. as a Perl programmer, we have very little control over this behavior. if you must go with this approach, i would trust top/ps whether than what the script output but again, you should research a bit and see if there are tools designed specially for this purpose. the toy-script approach can only get you this far. david -- s,.*,,e,y,\n,,d,y,.s,10,,s .ss.s.s...s.sss.s.ss s.s.s...s...s..s ...s.ss..s.sss..ss.sss.s s.s.s...ss.sss.s ..s..sss.s.ss.sss... ..ssss.sss.sss.s ,{4},|?{*=}_'y!'+0!$; ,ge,y,!#:$_(-*[./[EMAIL PROTECTED],b-t, .y...,$~=q~=?,;^_#+?{~,,$~=~ y.!-*-/:[EMAIL PROTECTED] ().;s,;, );,g,s,s,$~s,g,y,y,%,,g,eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl version on Solaris
Hi all, I'm trying to figure out exactly what I need to support and I'm getting conflicting inputs. Perhaps someone can shed some light on the subject. I'm trying to determine which version of perl ships by default with Solaris 8. I've been told two things: perl 5.005 and no perl is installed by default - both of which I find hard to believe. -Phil -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Frustrated newbie question
[EMAIL PROTECTED] wrote: Help. I'm a frustrated newbie who wants to use Perl to make my life easier. The following simple task is only one small part of a program I'm trying to put together to automate some things I currently do manually. I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. If the names don't include embedded spaces (i.e. all the whitespace is delimiters), you can use the default split() function for this: while() { print $_\n for split; } The perl one-liner for this would be: $ perl -lne 'print for split' myfile.txt ... My next Perl task after I get my list of one name per line, is to sort the list and eliminate duplicate names. Let's take it step by step. Consider: @arr = ; This reads all the input lines into an array. But we really want to split each line into the separate names, so we use map for this: @arr = map split, ; Sorting is trivial: @arr = sort map split, ; Eliminating duplicates can be done through a standard trick: @arr = do { my %seen; grep !$seen{$_}++, sort map split, }; Now @arr contains the unique names, in sorted order, ready to print out. The perl one-liner would be: perl -le 'print for grep !$seen{$_}++, sort map split, ' myfile.txt n.b., moving the sort from where it is to in front of the grep would be more efficient if the number of duplicates is large. HTH -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Frustrated newbie question
I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. Here is one way: while () { @line = split; print $_\n for @line; } let me know if you need explanation of what this does. HTH Jim -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Frustrated newbie question
Help. I'm a frustrated newbie who wants to use Perl to make my life easier. The following simple task is only one small part of a program I'm trying to put together to automate some things I currently do manually. I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. I currently use a macro with a text editor to clean up the file into the one name per line format. I can do this very quickly in contrast to the the last two hours I've spent trying to figure out how to get Perl to do this very simple task. Arrggh ! To simply things, I just tried to take the following string and print it out one name per line. my $x = name1 name2 name3; I've tried various schemes using regex's and the ///s operator. Most of the time I get syntax errors and the few times I get anything to work, it's not what I want. I did get this array structure to work: my @names = qw(name1 name2 name3); print $names[0] \n; print $names[1] \n; print $names[2] \n; So I then spent time unsuccesfully trying to figure out how to get my string split into the array. I couldn't get that to work either. More Arrggh ! Anyway, any help at this point will be appreciated. I'm hoping that in the long run the time I spend learning Perl will pay off, which it will if I can automate some of the tasks I do manually (with the help of macros in a text editor). My next Perl task after I get my list of one name per line, is to sort the list and eliminate duplicate names. Thanks again for any help. You are looking initially for the 'split' function. perldoc -f split So for instance your one line above: my $line = name1 name2name3; Can be broken into parts, my @parts = split(/\s+/, $line); The above says to split on one or more whitespace characters and store the result as a list in an array. Then you want to have a go at, perldoc -f push You can then loop over a series of lines storing each of the smaller arrays to a bigger array. That will give you your complete list. For sorting and assuring uniqueness you will want to check out: perldoc -f sort perldoc -f grep perldoc -f map Good luck, don't get frustrated (any more), and I guarantee Perl will open doors that a text editor macro can only dream of (unless we are talking emacs or something, but then we are really talking lisp)... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Frustrated newbie question
On Dec 5, 2003, at 9:53 AM, [EMAIL PROTECTED] wrote: [..] I'm trying to put together to automate some things I currently do manually. I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. [..] Slow down, breath, one step at a time. First off, if the file is OUTSIDE of the program it will help to read the lines of data into your program - so we will need something like open(FD, $file_name) or die unable to read file $file_name :$!; then we can 'read the lines in' my @list_oh_names; while(FD) { chomp; # take away those pesky end line my @tmp = split(/\s+/); push(@list_oh_names, @tmp); } close(FD); you can then check it with for(0..$#list_oh_names) { print $_ has $list_oh_names[$_]\n; } Now how to get the name of the file in my ($file_name) = @ARGV; would be a way, but I think YOU REALLY will want to become good friends with Getopt::Long be cool, impress your friends and co-workers... ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Frustrated newbie question
[EMAIL PROTECTED] wrote: Help. I'm a frustrated newbie who wants to use Perl to make my life easier. The following simple task is only one small part of a program I'm trying to put together to automate some things I currently do manually. I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. I currently use a macro with a text editor to clean up the file into the one name per line format. I can do this very quickly in contrast to the the last two hours I've spent trying to figure out how to get Perl to do this very simple task. Arrggh ! To simply things, I just tried to take the following string and print it out one name per line. my $x = name1 name2 name3; You can try this: my $x = name1 name2 name3; foreach ( split(/\s+/, $x) ) { printf %-s\n, $_; } Wags ;) I've tried various schemes using regex's and the ///s operator. Most of the time I get syntax errors and the few times I get anything to work, it's not what I want. I did get this array structure to work: my @names = qw(name1 name2 name3); print $names[0] \n; print $names[1] \n; print $names[2] \n; So I then spent time unsuccesfully trying to figure out how to get my string split into the array. I couldn't get that to work either. More Arrggh ! Anyway, any help at this point will be appreciated. I'm hoping that in the long run the time I spend learning Perl will pay off, which it will if I can automate some of the tasks I do manually (with the help of macros in a text editor). My next Perl task after I get my list of one name per line, is to sort the list and eliminate duplicate names. Thanks again for any help. ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Frustrated newbie question
Stuart Clemons wrote: I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. try: [panda]# perl -i -pe 's/\s+/\n/g' names.file this will make names.file look like: name1 name2 name3 ... I currently use a macro with a text editor to clean up the file into the one name per line format. I can do this very quickly in contrast to the the last two hours I've spent trying to figure out how to get Perl to do this very simple task. Arrggh ! To simply things, I just tried to take the following string and print it out one name per line. my $x = name1 name2 name3; I've tried various schemes using regex's and the ///s operator. Most of the time I get syntax errors and the few times I get anything to work, it's not what I want. you can use split, s/// or m//. for your purpose, they are bascially the same: #!/usr/bin/perl -w use strict; while(){ chomp; #-- #-- $names[0] = name1 #-- $names[1] = name2 #-- ... etc #-- my @names = split(/\s+/); #-- #-- you can even rewrite the above like: #-- #-- my @names = split; #-- #-- when you become more familiar with Perl #-- #-- #-- prints the name out like: #-- #-- name1 #-- name2 #-- name3 #-- ... #-- print join(\n,@names),\n; } __END__ you can also use m// like: my @names = /\S+/g; which search for one or more none space characters that are stick together and put each of them into @names. or you can use s/// like: s/\s+/\n/g; print $_\n; which search for one or more continueous spaces and translate them into a newline. Anyway, any help at this point will be appreciated. I'm hoping that in the long run the time I spend learning Perl will pay off, i think so. david -- s,.*,,e,y,\n,,d,y,.s,10,,s .ss.s.s...s.sss.s.ss s.s.s...s...s..s ...s.ss..s.sss..ss.sss.s s.s.s...ss.sss.s ..s..sss.s.ss.sss... ..ssss.sss.sss.s ,{4},|?{*=}_'y!'+0!$; ,ge,y,!#:$_(-*[./[EMAIL PROTECTED],b-t, .y...,$~=q~=?,;^_#+?{~,,$~=~ y.!-*-/:[EMAIL PROTECTED] ().;s,;, );,g,s,s,$~s,g,y,y,%,,g,eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sorter script [was: Frustrated newbie question]
On Friday 05 December 2003 10:53, [EMAIL PROTECTED] wrote: My next Perl task after I get my list of one name per line, is to sort the list and eliminate duplicate names. I have used the following script to sort and remove duplicate entries in flat text files. http://www.downloaddatabase.com/databasesoftware/db-sorter-script.htm Saskia -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Frustrated newbie question
does anyone know how to generate a java script alert window in perl? Or better a alert window generated by perl. Its for a field validation in a form...html -Original Message- From: david [mailto:[EMAIL PROTECTED] Sent: Friday, December 05, 2003 2:06 PM To: [EMAIL PROTECTED] Subject: Re: Frustrated newbie question Stuart Clemons wrote: I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. try: [panda]# perl -i -pe 's/\s+/\n/g' names.file this will make names.file look like: name1 name2 name3 ... I currently use a macro with a text editor to clean up the file into the one name per line format. I can do this very quickly in contrast to the the last two hours I've spent trying to figure out how to get Perl to do this very simple task. Arrggh ! To simply things, I just tried to take the following string and print it out one name per line. my $x = name1 name2 name3; I've tried various schemes using regex's and the ///s operator. Most of the time I get syntax errors and the few times I get anything to work, it's not what I want. you can use split, s/// or m//. for your purpose, they are bascially the same: #!/usr/bin/perl -w use strict; while(){ chomp; #-- #-- $names[0] = name1 #-- $names[1] = name2 #-- ... etc #-- my @names = split(/\s+/); #-- #-- you can even rewrite the above like: #-- #-- my @names = split; #-- #-- when you become more familiar with Perl #-- #-- #-- prints the name out like: #-- #-- name1 #-- name2 #-- name3 #-- ... #-- print join(\n,@names),\n; } __END__ you can also use m// like: my @names = /\S+/g; which search for one or more none space characters that are stick together and put each of them into @names. or you can use s/// like: s/\s+/\n/g; print $_\n; which search for one or more continueous spaces and translate them into a newline. Anyway, any help at this point will be appreciated. I'm hoping that in the long run the time I spend learning Perl will pay off, i think so. david -- s,.*,,e,y,\n,,d,y,.s,10,,s .ss.s.s...s.sss.s.ss s.s.s...s...s..s ...s.ss..s.sss..ss.sss.s s.s.s...ss.sss.s ..s..sss.s.ss.sss... ..ssss.sss.sss.s ,{4},|?{*=}_'y!'+0!$; ,ge,y,!#:$_(-*[./[EMAIL PROTECTED],b-t, .y...,$~=q~=?,;^_#+?{~,,$~=~ y.!-*-/:[EMAIL PROTECTED] ().;s,;, );,g,s,s,$~s,g,y,y,%,,g,eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl version on Solaris
On Dec 5, 2003, at 10:19 AM, Phil Schaechter wrote: [..] I'm trying to determine which version of perl ships by default with Solaris 8. I've been told two things: perl 5.005 and no perl is installed by default - both of which I find hard to believe. The official answer is 'yes'. It is possible to do a build of a solaris8 box and NOT take the perl release. It is possible to build the box and take the perl release. It is even possible to download the appropriate patch from sun and get the perl 5.6.1 - so it all sorta depends upon whom you were kvetching with about which of the TrueTruths is tru-er. So if vladimir: 56:] /usr/perl5/bin/perl -v This is perl, v5.6.1 built for sun4-solaris-64int (with 48 registered patches, see perl -V for more detail) then it is a build of perl that came from Sun. BUT then again vladimir: 57:] which perl /usr/local/bin/perl vladimir: 58:] whereis perl perl: /usr/bin/perl /usr/local/bin/perl vladimir: 59:] ls -li /usr/bin/perl /usr/local/bin/perl 17345 -rwxr-xr-x 3 root other 14684 Aug 30 2002 /usr/bin/perl 17345 -rwxr-xr-x 3 root other 14684 Aug 30 2002 /usr/local/bin/perl vladimir: 60:] would indicate that the Freak out there has opted to install an alternative build of Perl on their Solaris machine for ideological deviationalism... So yes, it is true that in Solaris7 there was NO perl by default, but with Solaris8 it became an option... HTH. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl version on Solaris
Hi all, I'm trying to figure out exactly what I need to support and I'm getting conflicting inputs. Perhaps someone can shed some light on the subject. I'm trying to determine which version of perl ships by default with Solaris 8. I've been told two things: perl 5.005 and no perl is installed by default - both of which I find hard to believe. Well, this: http://docs.sun.com/db/doc/805-6332/6j5vhemob?q=Perla=view Suggests that Solaris 8, at least more recent versions of it, are shipped with 5.005_03. Whether or not a particular package has been installed is probably up to the local admin/builder, etc. The Sun freeware archive also makes available a more recent version, for instance at my place of employment our Sun boxen come with 5.6.1 pre-installed but that is a local company choice rather than a Sun determined selection. HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
re: Frustrated newbie question
Thanks to all with the quick responses and possible solutions for splitting my names list into one name per line. I've tried a couple of them and they work great. You guys make it look so easy ! Using an array with 'Split' seemed to be a key part of the solution. I guess I was sort of on the right track. though I'm not sure when (or if) I would have figured it out. Anyway, thanks again to everyone for the help and support. I appreciate it. - Stuart -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Frustrated newbie question
On Dec 5, 2003, at 11:09 AM, [EMAIL PROTECTED] wrote: [..] You guys make it look so easy ! just think how weird you will be when your copy of Programming Perl 3rd Edition is the coffee stained collector's item right next to our copies of Programming Perl - the Pink Book - that was the first edition... Granted, we'll all be worm fodder when that stuff shows up on E-Bay... May I recommend that you think seriously about picking up it, and the learning perl and learning perl objects, references and modules - as they will help get you over the camal's hump. Using an array with 'Split' seemed to be a key part of the solution. I guess I was sort of on the right track. though I'm not sure when (or if) I would have figured it out. [..] Think a bit about what you just saw roll over the rollers at you - there were some of the basic 'perl-golfers' who were just teed up to swing swift one liners, as well as folks looking at transitioning your code into the more 'traditional' approach of application programming. Now comes the harder parts of the process: a. do this as a one liner each time b. keep the knowledge as a filter that takes stdin and woofs to stdout c. generate a piece of code that takes a file name and generates out put d. start adding more flags to it to make it do more stuff like take an input file name, and an output file name, maybe some regEx options from the command line e. wrap d. inside a GUI front end... ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Perl version on Solaris
Thanks - exactly what I was looking for. -Phil Well, this: http://docs.sun.com/db/doc/805-6332/6j5vhemob?q=Perla=view Suggests that Solaris 8, at least more recent versions of it, are shipped with 5.005_03. Whether or not a particular package has been installed is probably up to the local admin/builder, etc. The Sun freeware archive also makes available a more recent version, for instance at my place of employment our Sun boxen come with 5.6.1 pre-installed but that is a local company choice rather than a Sun determined selection. HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Perl Mysql
Hi there, Which modules i have to install in order to connect perl with mysql ?, in what order ?, My perl installation is on solaris 9. I already have mysql installed. Thanks for the help. Joe EchavarrÃa. __ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Finding Hosts On Lan - Re: hostname
What are you looking for? IP addresses for machines? Live IP Addresses? Physical Machines? DNS Information? DHCP Machines? Ethernet NIC Addresses? or some combination? What network structure are you using? NetBeui? TCP/IP? IPX/SPX? Other? All this information can be gathered with perl. Some easier than others. I have a script I wrote that pings IP's within a specified range, tells me whether the IP is in use or not, what Name is assigned the IP and whether the reverse lookup yields the same IP. (This script assumes ping is answered by machine being pinged.) With Linux or Unix machine and perl, the tools are there to find out just about anything you want about your network. At 02:45 PM 12/4/2003, Bob Showalter wrote: drieux wrote: On Dec 4, 2003, at 8:18 AM, Bob Showalter wrote: Thomas Browner wrote: Is there away to find all of the hostname on a lan with use of perl? [..] You can query DNS to get the hosts in a domain using nslookup, dig, host, or similar. For example: host -l mydomain.com If you want to talk to the resolver directly from Perl, you can use the Net::DNS module. first forgive the brief prefatory rant: rant Bad BOB! Not Nice Bob! No Cookie! /rant Oy vey! since what Bob has done with that 'host -l mydomain.com' is oblige us to go back and REALLY work out what in the DNS is a 'host' and what is the bloat in the DNS that is not actually a Host, not in the sense that most folks would think of. $ host -ltA mydomain.com (:~) [snip...] So a part of the unpleasantry, is what exactly is 'finding hosts on a Lan' really a question about... No argument there. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response Patrick J. Shoaf, IT Manager [EMAIL PROTECTED] Model Cleaners, Uniforms, Apparel 100 Third Street Charleroi, PA 15022 http://www.model-uniforms.com/http://www.model-uniforms.com Phone: 724-489-9553 ext. 105 or800-99 MODEL Fax: 724-489-4386 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Perl Mysql
Hi there, Howdy, Which modules i have to install in order to connect perl with mysql ?, in what order ?, My perl Excellent choice of combo! You'll want to install DBI It should come witht the mysql driver automatically. installation is on solaris 9. I already have mysql installed. Thanks for the help. HTH DMuey -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Replacing text
I have a script that reads text from a file and inserts text into different places depending on what it needs to do. But I use split to replace the text, i.e.: ($first_part, $second_part) = split #INSERT#TEXT#HERE#, $document, 2; print FILEHANDLE $firstpart, $text_to_insert, $secondpart; Is there a replace function in perl that would let me do something like replace #INSERT#TEXT#HERE, $text_to_insert;? I was going to write my own method but was curious if perl had something faster? Thanks in advance, -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Replacing text
Hi Dan, have you tried using a regular expression? I am using something like this for a similar purpose: not syntax-checked and quite ugly perl code open ($fh, $filename); # go through each line of the file while ($_ = $fh) { # replace globally in the default variable $_ s/#INSERT#TEXT#HERE/$text_to_insert/g; } close ($fh); /perl code Search for perlre in perl-doc for more information. HTH, Philipp Traeder On Sat, 2003-12-06 at 00:10, Dan Anderson wrote: I have a script that reads text from a file and inserts text into different places depending on what it needs to do. But I use split to replace the text, i.e.: ($first_part, $second_part) = split #INSERT#TEXT#HERE#, $document, 2; print FILEHANDLE $firstpart, $text_to_insert, $secondpart; Is there a replace function in perl that would let me do something like replace #INSERT#TEXT#HERE, $text_to_insert;? I was going to write my own method but was curious if perl had something faster? Thanks in advance, -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Replacing text
[EMAIL PROTECTED] wrote: I have a script that reads text from a file and inserts text into different places depending on what it needs to do. But I use split to replace the text, i.e.: ($first_part, $second_part) = split #INSERT#TEXT#HERE#, $document, 2; print FILEHANDLE $firstpart, $text_to_insert, $secondpart; Is there a replace function in perl that would let me do something like replace #INSERT#TEXT#HERE, $text_to_insert;? I was going to write my own method but was curious if perl had something faster? Thanks in advance, -Dan You should be able to use a regex(assuming the data you are looking for is in $_): if ( s/#INSERT#TEXT#HERE#/$text_to_insert/ ) { # success }else { # no hit } Wags ;) ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: Replacing text
Good news, Dan. That is arguably one of Perl's most famous features! Regular expresions (Perl's own) are very similar to what you would do with sed, if you are familiar with that. open IN, $input or die Unable to open $input for reading, $!, stopped; open OUT, $output or die Unable to open $output for writing, $!, stopped; print Munging $input, creating new file $output.\n; while ( IN ) { s/oldtext/newtext/g; # substitute (replace) oldtext with newtext, # g means globally if happens more than once on a line. print OUT; } close IN; close OUT; print Munge complete.\n; -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Dan Anderson Sent: Friday, December 05, 2003 3:11 PM To: [EMAIL PROTECTED] Subject: Replacing text I have a script that reads text from a file and inserts text into different places depending on what it needs to do. But I use split to replace the text, i.e.: ($first_part, $second_part) = split #INSERT#TEXT#HERE#, $document, 2; print FILEHANDLE $firstpart, $text_to_insert, $secondpart; Is there a replace function in perl that would let me do something like replace #INSERT#TEXT#HERE, $text_to_insert;? I was going to write my own method but was curious if perl had something faster? Thanks in advance, -Dan -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
formats
Is it possible to use more than one format in a script? I am parsing a log file to STDOUT and would like to be able to write to two (or more) different formats depending on the information found in the log. This is what I'm trying to do: 1. open and read logfile 2. if you find some_string print to STDOUT using TYPE_1 format 3. if you find other_string print to STDOUT using TYPE_2 format 5. continue parsing logfile, etc I can open and parse the logfile, my script breaks whenever I try to call more than one type of format. This doesn't seem to work for me, is this even possible? format TYPE_1 = Type: @ Gateway: @ Acct ID: @ $record_type,$gateway,$acct_id Start Date: @ Start Time: @ $start_date,$start_time . write TYPE_1; format TYPE_2 = Type: @ Gateway: @ Acct ID: @ $record_type,$gateway,$acct_id Start Date: @ Start Time: @ $start_date,$start_time Disconnect Date: @ Disconnect Time: @ $disco_date,$disco_time . write TYPE_2; Also, how would I go about keeping the filehandles open as it would be repetively writing each format. Thank you, Jose
Re: Reduce file size with Imager
Eamon Daly wrote: Hi, all. I'm using Imager to create gifs, but the resultant file sizes are /huge/. I'm writing the files out like so: Are you doing animations? If not, skip the GIFs. You can get much better depth [16 million] in a lot less space with JPEG files. Some of the compression algorithms avaiable are loss-free, too. No matter how small the color table, each pixel is still going to take its one byte when using GIF. I see that you set a gif_eliminate_unused flag, but I am sort of sceptical about how effective this will really be. I have never heard of a GIF making such optimizations. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: search and replace using regex
drieux wrote: Or we might use say $_ =~ s|\s*_||g; to clean out the preceeding 'white space'... ciao drieux I don't think so. That would be profoundly rude. One of the traditional courtesies of the HTML protocols was [it is now, like most courtesy , honored more in the breach than the observance, unfortunately] to make the source accessible and readable. Crowding tags together sans whitespace has a very contrary effect. Add in the neglect of newlines, and the HTML source becomes an irredeeemable slop. Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: formats
To just use it for STDOUT, it's pretty straight forward, switching the special $~ variable as needed. You're switching FORMATs not filehandles. There may be a shortcut but this is how I would do it for this problem: -Tom Kinzer _ format TYPE_1 = Im formated with type1: @ @|| $field1, $field2 . format TYPE_2 = IM FORMATTED WITH TYPE2: @ @ $field1, $field2 . open RECORDS, YourInput.log or die; while (RECORDS) { ($field1, $field2) = split; if ( m/YourPatternRegExHere/ ) { $~ = 'TYPE_1'; } else { $~ = 'TYPE_2'; } write; } close RECORDS; __END__ -Original Message- From: Jose Malacara [mailto:[EMAIL PROTECTED] Sent: Friday, December 05, 2003 6:40 PM To: [EMAIL PROTECTED] Subject: formats Is it possible to use more than one format in a script? I am parsing a log file to STDOUT and would like to be able to write to two (or more) different formats depending on the information found in the log. This is what I'm trying to do: 1. open and read logfile 2. if you find some_string print to STDOUT using TYPE_1 format 3. if you find other_string print to STDOUT using TYPE_2 format 5. continue parsing logfile, etc I can open and parse the logfile, my script breaks whenever I try to call more than one type of format. This doesn't seem to work for me, is this even possible? format TYPE_1 = Type: @ Gateway: @ Acct ID: @ $record_type,$gateway,$acct_id Start Date: @ Start Time: @ $start_date,$start_time . write TYPE_1; format TYPE_2 = Type: @ Gateway: @ Acct ID: @ $record_type,$gateway,$acct_id Start Date: @ Start Time: @ $start_date,$start_time Disconnect Date: @ Disconnect Time: @ $disco_date,$disco_time . write TYPE_2; Also, how would I go about keeping the filehandles open as it would be repetively writing each format. Thank you, Jose -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Frustrated newbie question
[EMAIL PROTECTED] wrote: Help. I'm a frustrated newbie who wants to use Perl to make my life easier. The following simple task is only one small part of a program I'm trying to put together to automate some things I currently do manually. I have a file whose format looks like this: name1 name2 name3 name4 name5 name6, etc. The names are separated by spaces. I need the names to be one name per line, like this: name1 name2 name3, etc. l_welk.txt: an-a-one an-a-twoan-a-three an-a-four an-a-fivean-a-six an-a-seven an-a-eightan-a-nine Greetings! E:\d_drive\perlStuffperl -w open IN, 'l_welk.txt' or die Too ossified, I guess $!; while (IN) { s/\s+/\n/g; print; } ^Z an-a-one an-a-two an-a-three an-a-four an-a-five an-a-six an-a-seven an-a-eight an-a-nine Joseph -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Reading from log
Hello all, I am looking for help with creating a digest of a log file. I have found a nice tutorial that should help on http://www.pageresource.com/cgirec/ptut14.htm. However, this tutorial expects to have values in list separated by | : he Rock|Cheer|Rock Bottom Triple H|Boo|Pedigree Stone Cold|Cheer|Stone Cold Stunner And I do have a log file, that looks like: ... Format count a 100 b51 c 130 d 5 e 6 Total: --- 292 ... And I need to go through that log and find that 292 and store it into variable. If it was something like 'total: 292', I might be able to do it, however the value is on completely new line and nothing precedes it. Is anyone willing to help me? I am a completely newbie in programming. Thank you for your time. danield -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Reading from log
danield writes: Hello all, I am looking for help with creating a digest of a log file. I have found a nice tutorial that should help on http://www.pageresource.com/cgirec/ptut14.htm. However, this tutorial expects to have values in list separated by | : he Rock|Cheer|Rock Bottom Triple H|Boo|Pedigree Stone Cold|Cheer|Stone Cold Stunner And I do have a log file, that looks like: ... Format count a100 b 51 c130 d 5 e 6 Total: --- 292 ... And I need to go through that log and find that 292 and store it into variable. If it was something like 'total: 292', I might be able to do it, however the value is on completely new line and nothing precedes it. Is anyone willing to help me? I am a completely newbie in programming. Thank you for your time. danield This is a very typical situation. You need to read each line of the log file in a loop, and when you see the line with Total: as its first field, set a flag. Then when you go thru the loop again, you test the flag to see if it is set. If it is, you extract the interesting data from the line you just now read. You may also want to reset the flag, depending on whether you wish to do anything else after this with the input file. The above logic is very awk-like; an even cleaner way is to write a little subroutine to read the line, and call that in a loop, testing for the Total: in field one. When you see it, call the read line routine again and extract the interesting data. This way, you do not need to use any flags. Flags are messy and old fashioned. It is far better to use the program counter instead of flags to keep track of what you are doing. -- And there came a writing to him from Elijah [2Ch 21:12] R. J. Brown III [EMAIL PROTECTED] http://www.elilabs.com/~rj voice 847 543-4060 Elijah Laboratories Inc. 457 Signal Lane, Grayslake IL 60030 fax 847 543-4061 - M o d e l i n g t h e M e t h o d s o f t h e M i n d -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Pattern matching
I went back to my books to refresh my memory on how to use references. Your suggestion help a lot, but the subroutine returns wrong values. I did some small modifications on the codes below , and tried it. It return perl-5.8.0-80.3.i386.rpm and samba-2.2.7-5.8.0.i386.rpm, which is wrong because: 1. The perl version available on the ftp server is higher. 2. The samba version already installed is higher than the one on the ftp server. my @remote_packages = qw(perl-5.8.0-88.3.i386.rpm samba-2.2.7-5.7.0.i386.rpm bob-5.3.2.4.1.rpm xml-2.5.2.1.rpm); my @installed_packages = qw(perl-5.8.0-80.3.i386.rpm samba-2.2.7-5.8.0.i386.rpm bob-5.3.2.4.1.rpm); # I expect perl-5.8.0-88.3.i386.rpm to be returned here. my $need_list = check_lists([EMAIL PROTECTED] , [EMAIL PROTECTED]); foreach my $pkg (@$need_list) { # $ftp_server-get($pkg) ; } # # sub check_lists { my ($src, $dst) = @_; #Making a quick pick hash my %src_hash = map { $_ = 1 } @$src; my @need_list; foreach my $key ( @$dst ) { push(@need_list, $key) unless(exists($src_hash{$key})); } # It should return only packages that are higher than those I've already installed. [EMAIL PROTECTED]; } # end of check_lists --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response