Re: perl and pattern

2012-02-23 Thread Igor Dovgiy
2012/2/23 Rob Dixon rob.di...@gmx.com Negative numbers aside, it seems more straightforward to insist that there are no non-digit numbers in the input, hence That's definitely an option, but I'm not in favor of 'double negation' conditionals usually, as they might be confusing. For example,

Re: Sending files efficiently with Net::SMTP

2012-02-23 Thread Igor Dovgiy
From the documentation (http://perldoc.perl.org/Net/SMTP.html) ... data ( [ DATA ] ) - initiate the sending of the data from the current message. DATA may be a reference to a list or a list. If specified the contents of DATA and a termination string .\r\nis sent to the server. And the result will

Re: Sending files efficiently with Net::SMTP

2012-02-23 Thread Igor Dovgiy
Argh, misunderstood the doc a bit. This line in my code: push @msg_content, \r\n; ... is redundant, the termination string will be added automatically by data() method. -- iD 2012/2/23 Igor Dovgiy ivd.pri...@gmail.com From the documentation (http://perldoc.perl.org/Net/SMTP.html) ... data

Re: perl and pattern

2012-02-22 Thread Igor Dovgiy
What a pleasant thread we've got here. ) Suppose a bit of my ranting won't spoil it much, will it? )) 2012/2/21 Vyacheslav agapov.sl...@gmail.com I'm new in perl and have many questions. And there's a place to ask them, believe me. ) This my first programm. Going straight to the point, I

Re: perl and pattern

2012-02-22 Thread Igor Dovgiy
-02-22 21:48, Igor Dovgiy wrote: Anyway, if you're looking for integers only, as assumed previously, the corresponding check should be made of this: *match the beginning of the line marker, then, optionally, a minus sign, then any number of digits, then the end of the line marker*, or just

Re: Keyboard scan codes with Term::Screen

2012-02-20 Thread Igor Dovgiy
Hi Sean, I don't have Term::Screen installed, but I checked its source - and it looks like whenever some 'non-function' (i.e., not navigational) key is pressed, getch() just gives out the corresponding symbol. Perhaps you'd just check for the spacebar and enter key values (32 and 10,

Re: looping through an array with for

2012-02-15 Thread Igor Dovgiy
Hi Jim, Well, instead of asking at each step, whether the last element is processed or not, it's slightly better to exclude it from the loop: for my $i (0..$#keyFields - 1) { printf %s %s, $keyFields[$i], $match; } printf %s %s, $keyFields[-1], $lastmatch; But yes, I guess your last approach

Re: How to process just part of a file

2012-02-09 Thread Igor Dovgiy
First, we should make sure that we can recognize the beginning and the end of section within CRONDMP file itself. For example, let's define my $SEC_START = '## SECTION START', my $SEC_END = '## SECTION END'; When the source file contains both of these, and so the section we need is clearly

Re: Editing line of text.

2012-02-08 Thread Igor Dovgiy
Hi Sean, Let's follow the documentation, shall we? ) -- readline(PROMPT[,PREPUT]) Gets an input line, with actual GNU Readline support. Trailing newline is removed. Returns undef on EOF. PREPUT is an optional argument meaning the initial value of input. The optional argument PREPUT is granted

Re: How to Digest::CMAC-add($json)

2012-02-07 Thread Igor Dovgiy
It's not an encoding issue. It's a 'storage' issue. ) JSON::to_json returns a string, with UTF8 flag on. JSON::encode_json returns a bytecode (sequence of octets), with UTF8 flag off. -- iD 2012/2/7 John Refior jref...@gmail.com On Mon, Feb 6, 2012 at 11:21 PM, John Refior jref...@gmail.com

Re: need guidance on encode JSON and sorting

2012-02-06 Thread Igor Dovgiy
That's what the documentation says: ... $json = $json-canonical([$enable]) If $enable is true (or missing), then the encode method will output JSON objects by sorting their keys. This is adding a comparatively high overhead. ... So I guess you'd have to use something like that: my $ret_json =

Re: Parsing Question

2012-02-01 Thread Igor Dovgiy
Just my $0.02... can't help offering a slight rewrite of David's great program. Now it's runnable on 5.010 and earlier, and should give out some warnings if hoststatus sections are somehow corrupt: $|++; # comment it out if you don't need to buffer the output my $section_started; my ($host,

Re: Dereferencing an array

2012-01-27 Thread Igor Dovgiy
Hi Rob, Just'd like to add my $0.02 to the brilliant solutions you offered. ) You can access the anonymous arrays from @desc using foreach my $rest (@desc) { print @$rest\n; } Or just... say @$_ for @desc; ... if one prefers conciseness - and is able to use 5.010, of course. ) But

Re: Collecting variables from Hash

2012-01-23 Thread Igor Dovgiy
Hi Pradeep, use List::Util qw( sum ); use constant { SUFFICIENT_SUCCESS = 244 } ... my $success = sum( map { /success$/ ? $results_href-{$_} : () } keys %$results_href ); ... return $success == SUFFICIENT_SUCCESS; -- iD 2012/1/22 Pradeep Patra smilesonisa...@gmail.com Hi, I have a hash

Re: Difference between and grep EXPR,

2012-01-20 Thread Igor Dovgiy
2012/1/20 Andrey P andrey.y...@gmail.com Hi! I don't understand why I need to use a list assignment for say scalar(()=$fh); but not for say scalar(grep /./, $fh); Because grep gives a list context to its second operand, just like the nuke ( ()= ) operator does. ) Remember, a

Re: How to merge multiple array elements

2012-01-16 Thread Igor Dovgiy
2012/1/15 Pradeep Patra smilesonisa...@gmail.com I want to merge more than 2 arrays. @array = (@array1,@array2,@array3,@array4); print Array elements:@array; It works and displays 1-12. But I need something different because i dont know the value of n beforehand. What do you mean by

Re: base64 to hex conversion

2012-01-16 Thread Igor Dovgiy
Hi Ramprasad, Perhaps... *use MIME::Base64 qw/decode_base64/;* *...* *my $res = unpack('H*', decode_base64($source));* ...will do the trick? ) -- iD 2012/1/16 Ramprasad Prasad ramprasad...@gmail.com Hello what is the best way to convert base64 to hex I am currently using

Re: Appending extra characters to file name

2012-01-05 Thread Igor Dovgiy
Hi Alex, Your script should be like that: $oldfile = $file; chomp($oldfile); my $newfile = $oldfile . .x; ... as $file (and $oldfile, which is redundant btw) ends with \n. Besides, it'd be much easier to collect all the files in the given directory with fileglob. -- iD 2012/1/5 Alex Ardin

Re: File Size Script Help - Working Version

2012-01-03 Thread Igor Dovgiy
Hi folks, happy new year to everyone. ) John, you're right, of course. ) The filenames in nested directories could well overlap, and using $File::Find::name would be safer. Didn't think of that as a big problem, though, as original script (with 'opendir') ignored all the nested folders overall.

Re: File Size Script Help - Working Version

2011-12-30 Thread Igor Dovgiy
Hi Jonathan, Argh, really stupid mistake by me. ) But let's use it to explain some points a bit further, shall we? A skilled craftsman knows his tools well, and Perl programmer (with CPAN as THE collection of tools of all sizes and meanings) has an advantage here: even if documentation is a bit

Re: File Size Script Help - Working Version

2011-12-30 Thread Igor Dovgiy
Hi John, yes, good point! Totally forgot this. ) Adding new files to a directory as you browse it is just not right, of course. Possible, but not right. ) I'd solve this by using hash with filenames as keys and collected 'result' strings (with md5 and filesizes) as values, filled by File::Find

Re: What does = means?

2011-12-30 Thread Igor Dovgiy
Hi Xi, You're looking only for 'p' letters, not D and O? Why? Anyway, generic solution will be something like... my %seen; my @repeated = grep { /some regex here/ $seen{$_} N } @source_array; ... where N is how many times the symbols should appear in the source array to be counted as

Re: What does = means?

2011-12-30 Thread Igor Dovgiy
Oh my, of course it should be... my @repeated = grep { /some regex here/ ++$seen{$_} N } @source_array; ... to work properly. -- iD 2011/12/30 Igor Dovgiy ivd.pri...@gmail.com Hi Xi, You're looking only for 'p' letters, not D and O? Why? Anyway, generic solution will be something like

Re: problem with passing variables

2011-12-30 Thread Igor Dovgiy
Hi Mark, If your variables are strictly internal and by no means might be ever tainted (read: user input), what you're doing is mostly ok. But you need to quote the dates passed within query itself, like this: my $sql = qq/SELECT * FROM `events` WHERE `date` BETWEEN '$begin_time' AND

Re: problem with passing variables

2011-12-30 Thread Igor Dovgiy
If you pass into SQL query something assigned by user, use placeholders by all means. ) It's not that hard, but it'll save you a lot of headaches, believe me. ) 2011/12/30 Mark Haney ma...@abemblem.com But there's another (and in my opinion, usually better) way: using prepared sql statement:

Re: File Size Script Help - Working Version

2011-12-30 Thread Igor Dovgiy
Great work, Jonathan! Notice how simple your script has become - and that's a good sign as well in Perl. :) We can make it even simpler, however. As you probably know, Perl has two fundamental types of collections: arrays (where data is stored as a sequence of elements, data chunks) and hashes

Re: File Size Script Help - Working Version

2011-12-29 Thread Igor Dovgiy
Hi Jonathan, Let's review your script a bit, shall we? ) It's definitely good for a starter, but still has some rough places. #!/usr/bin/perl # md5-test.plx use warnings; use strict; use File::Find; use Digest::MD5; use File::Spec; So far, so good. ) my $dir = shift ||

Re: passing arguments to perl function with - in the string

2011-11-29 Thread Igor Dovgiy
Hi Satya, Might I suggest to look up a bit into the function's source code? Because it's, well, pretty normal to call subs like that: ... some_func_call(-chan_range = $beg-$end) ... Of course, $beg and $end variables should be defined already (and contain numeric values, as I see). If not,

Re: sprintf function

2011-11-29 Thread Igor Dovgiy
googlesh perl is_numeric = http://www.perlmonks.org/?node_id=609478 qq{ Scalar::Util http://search.cpan.org/perldoc?Scalar%3A%3AUtil provides access to the underlying Perl API looks_like_number routine which Perl itself uses internally. } 2011/11/29 Chris Stinemetz chrisstinem...@gmail.com How

Re: Question regarding file stat setgid determination.

2011-10-31 Thread Igor Dovgiy
Hi Daniel, There's no such thing as boolean literals [true/false] in Perl. ) Remember these weird '1's at the end of .pm files? ) Or constructs like while(1)? ) And frankly speaking, I don't think there's a big need for these literals. Every value (scalar or list, doesn't matter) can be well and

Re: regex help

2011-10-18 Thread Igor Dovgiy
Maybe this'll be helpful. ) my $time_rx = qr/(?timestamp (?hour \d{2} ) (?: :\d{2} ){2} ) /x; my $cell_record_rx = qr/CELL \s+ (?cell_number \d+) \s+

Re: Run perl scripts in Windows

2011-10-18 Thread Igor Dovgiy
Hello Remy, I guess you may either convert this script with something like perl2exe (or similar solutions), or use the portable version of Strawberry Perl - http://strawberryperl.com/download/5.12.3.0/strawberry-perl-5.12.3.0-portable.zip - to run it. -- iD 2011/10/18 Remy Guo

Re: How to put an AND in a regex?

2011-10-13 Thread Igor Dovgiy
Hmm, probably you should. To use two of them in AND combination, just... use two of them. ) /^(?![[:upper:]][[:upper:]])(?!\d)/ And it gets even better: you may mix any number of look-aheads in a single regex this way. ) -- iD 2011/10/13 Hamann, T.D. (Thomas) ham...@nhn.leidenuniv.nl Hi,

Re: don't know where to start??? comparing files

2011-10-13 Thread Igor Dovgiy
May be this'll help? ) #!/usr/bin/perl use strict; use warnings; die 'Usage: ' . __FILE__ . file1[ file2...]\n unless @ARGV; my $ref_file = 'ref.txt'; my $new_file = 'new.txt'; open my $ref_fh, '', $ref_file or die Failed to open reference file - $!\n; my %limits_for; while ($ref_fh) {

Re: encoding and PDF::API2

2011-10-07 Thread Igor Dovgiy
Hi Marcos, my %pdf_info = $pdf-info(); foreach (keys $pdf_info) { $pdf_info{$_} =~ s/[^\x00-\xFF]//g; } Perhaps that'll do? ) -- iD 2011/10/7 marcos rebelo ole...@gmail.com Hi all I'm trying to get the info from a PDF with a code like:

Re: Capitalizing Acronyms

2011-10-07 Thread Igor Dovgiy
You know, it shouldn't be mile long. ) $string =~ s! \b (?=[a-z]{3,4}) ([aeiouy]{3,4}|[^aeiouy]{3,4}) \b !\U$1!igx; -- iD 2011/10/7 Marc sono...@fannullone.us On Oct 6, 2011, at 4:44 PM, Jim Gibson wrote: You should go back to your original character class of [bcdfghjklmnpqrstvwxz]