Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

dasgar's scratchpad

by dasgar (Curate)
on Aug 12, 2010 at 05:21 UTC ( #854576=scratchpad: print w/replies, xml ) Need Help??

HTML::TokeParser test

use strict; use warnings; use LWP::Simple; use HTML::TokeParser; my $url = ""; my $page = get($url); my $p = HTML::TokeParser->new(\$page) || die "problem: $!\n";

For Limbic~Region:
From CB:    Limbic~Region: Assuming you are limited to only core modules (5.8.8) and you needed to determine what month it was N months ago and how many days in that month, how would you do it?

After asking a stupid question, I tried coming up with a doable solution. I doubt that it's the "best" answer, but I think it works. Providing the script below with a negative number tells it to go back X months and providing it with a positive number tells it to go forward X months.

use strict; use warnings; my $delta = int(shift); my $delta_years = int(abs($delta)/12); my $delta_months = abs($delta) % 12; my $cur_month = (localtime)[4]; my $cur_year = (localtime)[5]+1900; if ($delta < 0) { $delta_years *= -1; $delta_months *= -1; } if ($delta_months < 0) { if (abs($delta_months) > $cur_month) {$delta_years--;} } else { if ($delta_months > (12 - $cur_month)) {$delta_years++;} } my $new_month = $cur_month + $delta_months; my $new_year = $cur_year + $delta_years; my @days = qw(31 28 31 30 31 30 31 31 30 31 30 31); my @months = qw(January February March April May June July August Sept +ember October November December); my $answer = $days[$new_month]; if (($new_month == 2) && (Is_Leap_Year($new_year))) {$answer = 29;} print "$months[$new_month] has $answer days.\n"; ########### sub Is_Leap_Year { my $year = shift; if (($year % 100) == 0) {return 1;} if (($year % 4) == 0) { if (($year % 25) == 0) { return 0; } else {return 1;} } else {return 0;} }

File slurp example:

use strict; my $file; open(FH,"<",$file) || die "Unable to open file: $!\n"; { local $/; $file = <FH>; } close(FH);

Help for amittleider.

use strict; my @lc_alpha = ('a'..'z'); foreach my $file (@ARGV) { my $error = 0; my %count; foreach my $alpha (@lc_alpha) {$count{$alpha} = 0;} open(DAT,"<",$file) || $error++; if ($error) { print "Unable to open file '$file': $!\n"; print "Skipping the file.\n"; } else { while (<DAT>) { my (@chars) = ($_ =~ m/([a-z])/gi); foreach my $char (@chars) { $count{lc($char)}++; } } close(DAT); print "The file '$file' has the following character counts:\n"; foreach my $alpha (@lc_alpha) { print " $alpha -- $count{$alpha}\n"; } print "\n"; } }
Log In?

What's my password?
Create A New User
[ELISHEVA]: but it seems that the DBD::CSV layer on top of it doesn't
[afoken]: Also: All other attributes that start with csv_ and are not described above will be passed to Text::CSV_XS (without the csv_ prefix).
[Discipulus]: what about a good 'ol SOPW?
[erix]: Giro d'Italia won by Dumoulin (peccato Nibali)
[ELISHEVA]: csv_detect_bom doesn't work either
[erix]: (SCNR)
[ELISHEVA]: I may have to resort to SOPW - but was hoping that this would be something simple
[erix]: I'd just remove the BOM, it is pretty simple
[ELISHEVA]: Simple yes. and I did consider that. but this isn't one off . An important data source that I don't control is generating bom prefixed utf8 files and I'd rather not have to be munging files every few months.
[erix]: on teh other hand a SOPW is pretty much garanteed to get an answer from tux (and probably the module fixed)

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2017-05-28 20:31 GMT
Find Nodes?
    Voting Booth?