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

dada's scratchpad

by dada (Chaplain)
on Jun 03, 2004 at 19:22 UTC ( #360383=scratchpad: print w/replies, xml ) Need Help??

package Tie::StorableHash; use Storable; sub TIEHASH { my $class = shift; my $storage = shift || "autostorage"; my $instance = shift || {}; $instance = retrieve $storage if -e $storage; return bless { value => $instance, storage => $storage, } => $class; } sub FETCH { #print "FETCH got $_[1]\n"; return $_[0]->{value}->{$_[1]}; } sub STORE { #print "STORE got $_[1] = $_[2]\n"; $_[0]->{value}->{$_[1]} = $_[2]; store $_[0]->{value}, $_[0]->{storage}; } sub DESTROY { undef $_[0]; } package main; tie %karma, Tie::StorableHash, "autostorage", {}; print "karma=%karma\n"; print "$karma{dada}\n"; $karma{dada}++; print "$karma{dada}\n"; $karma{larsen} = { value => 1000, comment => "troppo", } unless exists $karma{larsen}; print "$karma{larsen}->{value}\n";


here's the bug (tested with perl 5.6.(0..1) on Win32):

use warnings + close(STDERR) causes the angle brackets operator (eg. <FILE>) to fail.

take this little script and save it to a file (we'll call it dree.pl):

use warnings; close (STDERR); open(ME, "$0"); while (<ME>) { print; } close ME;
now execute it (perl dree.pl) and it returns only the first line of the script. if you comment close(STDERR), the whole script is printed out.


for PodMaster:
use Win32::API 0.20; my $GetFullPathName = new Win32::API( 'kernel32', 'GetFullPathName', 'PNPP' => 'N', ); my $GetLongPathName = new Win32::API( 'kernel32', 'GetLongPathName', 'PPN' => 'N', ); my $file = $ARGV[0] || 'twig.pm'; my $full = "\0" x 2048; my $name = 0; my $rc; $rc = $GetFullPathName->Call( $file, 2048, $full, $name ); if($rc == 0) { die "GetFullPathName failed ($^E)\n"; } else { $full = unpack('A*', $full); print "GetFullPathName returned '$full'\n"; my $long = "\0" x 2048; $rc = $GetLongPathName->Call( $full, $long, 2048 ); $long = unpack('A*', $long); if($rc == 0) { die "GetLongPathName failed ($^E)\n"; } else { print "GetLongPathName returned '$long'\n"; } }

for BrowserUk:

#! perl -sw use strict; use Inline C => 'DATA'; my $num = '1'; print looks_like_number($num), $/; __DATA__ __C__ int looks_like_number(SV* var) { dTHX; return Perl_looks_like_number(aTHX_ var); }

for giant:

package Tie::PrintfScalar; sub TIESCALAR { my($class, $printf) = @_; return bless { value => undef, printf => $printf, }; } sub STORE { my($self, $value) = @_; return $self->{value} = $value; } sub FETCH { my($self) = @_; return sprintf($self->{printf}, $self->{value}); } sub DESTROY { undef ${$_[0]}; } 1; package main; my $nr; tie $nr, Tie::PrintfScalar, '%02d'; $nr = 2; print "$nr\n";

callback.c:

#include <stdio.h> #include <windows.h> typedef int (__stdcall * mycallback)(int); int do_callback( mycallback cb, int v) { int r = cb(v); return r; } int CALLBACK callback( int a) { printf("callback got %d\n", a); return a*2; } int main(int argc, char* argv[]) { int r; r = do_callback(callback, 21); printf("main got %d\n", r); return 0; }
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2023-12-09 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (37 votes). Check out past polls.

    Notices?