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 > From the documentation (http://perldoc.perl.org/Net/SMTP.html) > ...

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\n"is sent to the server. And the result wil

Re: perl and pattern

2012-02-23 Thread Igor Dovgiy
2012/2/23 Rob Dixon > > 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, I use only wh

Re: perl and pattern

2012-02-22 Thread Igor Dovgiy
initely the bad thing to teach the beginners. ) So yes, it's safer to go with [0-9]. TIMTOWTDI, of course: using /a modifier alongside \d-\w-\s. It's even better (as it 'fixes' the context even for compound regexes, as I understand), but is available only since 5.14. -- iD 2012

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 > 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 see... Good. But i

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, respectively)

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 approa

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 ma

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 onl

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 > On Mon, Feb 6, 2012 at 11:21 PM, John Refior wrote: > > > I am trying to create

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, $state

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

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 > Hi, > I have a hash reference as follows:

Re: Difference between <> and grep EXPR, <>

2012-01-20 Thread Igor Dovgiy
2012/1/20 Andrey P > 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 context is what's

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 > Hello > > what is the best way to convert base64 to hex > > I am currently using > >

Re: How to merge multiple array elements

2012-01-16 Thread Igor Dovgiy
2012/1/15 Pradeep Patra > 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 'n'? Size of the f

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 Ardi

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. J

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 (wh

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 > But there's another (and in my opinion, usually better) way: using > prepared sql statement: > my $sth = $dbh->

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 '$end_time'/

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 > Hi Xi, > > You're looking only for 'p' letters, not D and O? Why? > > Anyway, generic

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 dupl

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 tar

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 va

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 || '/Users/j

Re: sprintf function

2011-11-29 Thread Igor Dovgiy
googlesh "perl is_numeric" => http://www.perlmonks.org/?node_id=609478 qq{ Scalar::Util provides access to the underlying Perl API looks_like_number routine which Perl itself uses internally. } 2011/11/29 Chris Stinemetz > How can I check that t

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, war

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: 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 > hi all, > I ha

Re: regex help

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

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_f

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) > > Hi, > > I am trying to write

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 > On Oct 6, 2011, at 4:44 PM, Jim Gibson wrote: > > > You should go back to your original character class of > [bcdfghjklmnpqrstvwxz] > > Making this

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 > Hi all > > I'm trying to get the info from a PDF with a code like: > > ### > >