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

Neighbour's scratchpad

by Neighbour (Friar)
on Nov 11, 2009 at 12:57 UTC ( #806481=scratchpad: print w/ replies, xml ) Need Help??

Inline substitution

my $data = "spamspamspamspamusefuldataspamspamspam"; print("Data: " . (map { s/spam//g;$_; } ($data))[0] . "\n");
Note that this modifies $data.

Smart matching

Why do 2 vars with the following Devel::Peek::Dump output not match using !~~?
if ($expected !~~ $got) { print("Smartmatch failed comparing data\n"); print("Expected:\n"); Devel::Peek::Dump $expected; print("Got:\n"); Devel::Peek::Dump $got; }
Smartmatch failed comparing data Expected: SV = PV(0x3e57478) at 0x3e80f80 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x356d5f0 "0.00"\0 CUR = 4 LEN = 8 Got: SV = PV(0x3e57498) at 0x3e9e4f0 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0xe0422e0 "0.00"\0 CUR = 4 LEN = 8
Answer: There is no such operator as !~~. Perl interprets it as $expected !~ (~ $got) which is entirely different from !($expected ~~ $got)

Excel reading issues

First the calling code from the testsuite:
sub ReadXLS { my $ar_data; print("Reading from xls..."); $benchmark = Benchmark::timeit(1, sub { $ar_data = $interface->Exc +elBinary_ReadData("$Incoming_Dir/items.xls"); }); print(scalar @{$ar_data} . " records in [" . $benchmark->real . " +seconds], [" . (scalar @{$ar_data} / $benchmark->real) . " records/s] +\n"); return $ar_data; }
And the librarydata that provides the ReadData-function:
$Interfaces::ExcelBinary::Headers = []; # cell_handler (Workbook, Sheet_index, Row, Col, Cell) # Called by Spreadsheet::ParseExcel for every cell encountered. sub cell_handler { my ($workbook, $sheet_index, $row, $col, $cell) = @_; if ($row == 0) { push(@{$Interfaces::ExcelBinary::Headers}, $cell- +>value); } if ($row > 0) { Data::Dump::dd($Interfaces::ExcelBinary::Headers); $workbook->ParseAbort(1); exit; } } # ReadData (Filename, [WorkSheetID]) returns $ar_data # Reads data from the given file (which should be a BIFF-formatted .xl +s-file) and the given worksheet (by name or number (0-based)). # If the supplied worksheetID is a number, a negative number -n will r +efer to the n-to-last worksheet. sub ReadData { my ($self, $FileName, $WorkSheetID) = @_; my $ExcelParser = Spreadsheet::ParseExcel->new( CellHandler => \&cell_handler, NotSetCell => 1, ); print("Parsing\n"); my $WorkBook = $ExcelParser->parse($FileName); print("Done parsing\n"); exit;



Remove common prefix

Idea based on the palindrome-detection algorithm.
#!/usr/bin/perl use warnings; use strict; my $text1 = 'aapnootmies'; my $text2 = 'aapnogeenaap'; my $text3 = $text1 . reverse($text2); $text3 =~ s/(.*)(.*)(??{reverse $1})/$2/; print("Without common start [$text3]\n");
moritz: oh, that's a nice combination of "clever" and "stupid" :-)
He then fixed it up to be like this:
#!/usr/bin/perl use warnings; use strict; my $text1 = 'aapnootmies'; my $text2 = 'aapnogeenaap'; my $text3 = $text1 . reverse($text2); $text3 =~ m/(.*)(.*)(??{quotemeta reverse $1})/s; my $common = $1; $text1 =~ s/^\Q$common//; $text2 =~ s/^\Q$common//; print "[$text1]\n[$text2]\n";
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (16)
As of 2014-08-22 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (163 votes), past polls