Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

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?

What's my password?
Create A New User
[choroba]: So the "a" is different, not the "s" ;-)
[LanX]: people knowing that it's a workaround will pronounce it right
[LanX]: well
[LanX]: Maße and Masse are two very different words.
LanX (measures/mass)
[Tanktalus]: choroba: thanks, not sure why it wasn't doing that for me, but will try to figure it out. :)
[LanX]: can I copy a authotification cookie from mozilla and reuse it in LWP::Useragent?
[LanX]: nevermind
Tanktalus is at work, ssh'd home, using his cbstats bridge to talk on perlmonks CB. :)
[Tanktalus]: anyway, next is to figure out how to get postgres to agree that these are the same :)

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2018-03-21 15:53 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (269 votes). Check out past polls.