Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

ikegami's scratchpad

by ikegami (Patriarch)
on Aug 16, 2004 at 23:32 UTC ( [id://383504]=scratchpad: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    >type script.bat
    @echo off
    ...
    testb=
    testa=abc
    testb=def
    
  2. or download this
    package My::XML::Generator;
    
    ...
                ]),
            ]);
        }
    
  3. or download this
    use IO::Handle ();  # For "flush" method.
    
    ...
    }
    
    print("crlf\n");
    
  4. or download this
    use IO::Handle ();  # For "flush" method.
    
    ...
    STDOUT_BIN->flush();     
    
    print("crlf\n");
    
  5. or download this
    >perl -v
    
    ...
    -D100 L10
    0B27:0100  63 72 6C 66 0D 0A 72 61-77 0A 63 72 6C 66 0D 0A   crlf..raw
    +.crlf..
    -Q
    
  6. or download this
    use strict;
    use warnings;
    ...
    
    for (         $min .. $max) { print(":"); <STDIN>; last; }  # 2.2MB
    for ( reverse $min .. $max) { print(":"); <STDIN>; last; }  # 239MB
    
  7. or download this
    use File::Basename  qw( fileparse );
    use IO::Dir         qw( );
    ...
    
       return "$d${n}[$max]$e";
    }
    
  8. or download this
    sub get_iter {
       my $pass = 0;
    ...
    while ($_ = $i->()) {
       print("$_\n");
    }
    
  9. or download this
    sub get_iter {
       my $pass = 0;
    ...
    while ($_ = $i->()) {
       print("$_\n");
    }
    
  10. or download this
    sub get_fibonacci_iter {
       my ($x, $y) = (0, 1);
    ...
    my $i = get_fibonacci_iter();
    print($i->(), "\n")
       for 1..40;
    
  11. or download this
    my $mask = 0x06000003; # or whatever
    
    ...
       last if not $val;
       $val = ($val - 1) & $mask;
    }
    
  12. or download this
    0x00000000
    0x00000001
    ...
    0x06000001
    0x06000002
    0x06000003
    
  13. or download this
    sub slice_ref {
       return \@_;
    ...
    print("After inserting into bar:\n");    # Doesn't work:
    print('foo: ', join(', ', @foo), "\n");  # foo: a, 2, 3, 4, 5
    print('bar: ', join(', ', @bar), "\n");  # bar: a, 6, 2, 3
    
  14. or download this
    perl -M"ActivePerl::DocTools"
         -e"ActivePerl::DocTools::UpdateHTML();
            ActivePerl::DocTools::WriteTOC();"
    
  15. or download this
    use URI ();
    use File::Spec::Unix ();
    ...
    # ------
    # http://www.faqs.org/rfcs/
    # http://www.server.com/
    
  16. or download this
    system("... ...")
    system("...", "...", "...")
    ...
    IPC::Open3
    IPC::Run
    IPC::Run3
    
  17. or download this
    /^(?:(?!$re).)*$/          # NOT re
    /$re1|$re2/                # re1 OR re2
    /^(?=.*$re1)(?=.*$re2)/    # re1 AND re2
    
  18. or download this
    sub create_closure {
       my $var = shift;
    ...
    # around $var. I don't know if "closes"
    # is the official terminology, but
    # that's what's happening.
    
  19. or download this
    sub scale_dimentions {
       my ($width, $height, $max_width, $max_height) = @_;
    ...
    
    printf("%d,%d$/", scale_dimentions(2272, 1704, 150, 150));  # 150,112
    printf("%d,%d$/", scale_dimentions(1704, 2272, 150, 150));  # 112,150
    
  20. or download this
    my @ranges = (
       [ 0 .. 2 ],
    ...
    
    print(join(' ', @$_), $/)
       foreach @results;
    
  21. or download this
    my @lists = (
       [ ... ],
    ...
    
    print(join(' ', @$_), $/)
       foreach @results;
    
  22. or download this
    # Add $value to sorted @array, if it's not already there.
    my $idx = binsearch { $a <=> $b } $value, @array;
    splice(@array, ~$idx, 0, $value) if $idx < 0;
    
  23. or download this
    sub binsearch(&$\@;$$) {
       my  $compare = $_[0];
    ...
    }
    
    sub _unsigned_to_signed { unpack('j', pack('J', $_[0])) }
    
  24. or download this
    $i = 4;       print($i)   while ($i--);  #  3210
    $i = 4;  do { print($i) } while ($i--);  # 43210
    
  25. or download this
    $a = something;  # something is executed in a scalar context.
    @a = something;  # something is executed in a list   context.
    ...
       print(scalar(localtime));  # Fri Oct  1 15:05:32 2004
    }
    # Refer to wantarray in perlfunc.
    
  26. or download this
    sub nearest {
       my ($num) = @_;
    ...
    
       return int($num + 0.5) * $f;
    }
    
  27. or download this
    sub nearest {
       my ($num, $digits) = @_;
    ...
    
       return int($num + 0.5) * $f;
    }
    
  28. or download this
    $stmt = 'SELECT Field1, Field2 FROM Table';
    $href = { map { @$_ } @{$dbh->selectall_arrayref($stmt)} };
    ...
    #    Row2Field1 => Row2Field2,
    #    ...
    # };
    
  29. or download this
    $stmt = 'SELECT Field1, Field2 FROM Table';
    $href = $dbh->selectall_hashref($stmt, 'Field1');
    ...
    #    Row2Field1 => { Field1 => Row2Field1, Field2 => Row2Field2 },
    #    ...
    # };
    
  30. or download this
    # Serializes an array, a hash or a list which contains only
    # strings and undefs. Everything else will be stringified.
    ...
          )
       } split(/\|/, $_[0]);
    }
    
  31. or download this
    # Untested.
    
    ...
    # End HTML.
    print($q->end_form());
    print($q->end_html());
    
  32. or download this
    sub flush {
       my $h = select($_[0]); my $af=$|; $|=1; $|=$af; select($h);
    }
    
  33. or download this
    package MyStruct;
    
    ...
       $x->Counter++;                      print($x->Counter, "\n");  # 5
       $x->Counter += 1;                   print($x->Counter, "\n");  # 6
    }
    
  34. or download this
    # This \$var syntax of open() requires Perl 5.8.0 or higher.
    use 5.8.0;
    ...
    }
    
    print("\$output contains:\n$output");
    
  35. or download this
    Windows Registry Editor Version 5.00
    
    ...
    
    [HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
    @="cmd.exe /k \"cd %L\""
    
  36. or download this
    use strict;
    use warnings;
    ...
    test 3: bypassed
    test 4: bypassed
    test 5: bypassed
    
  37. or download this
    @status = sort {
       my $mtime_a = (stat("$target_dir\\$a"))[9];
       my $mtime_b = (stat("$target_dir\\$b"))[9];
       $mtime_a <=> $mtime_b
    } @status;
    
  38. or download this
    @status = (
       map  { $_->[0] }
    ...
       map  { [ $_, stat("$target_dir\\$_"))[9] ] }
       @status
    );
    
  39. or download this
    use Alorithm::Loops;
    
    ...
       ];
    }
    
  40. or download this
    use strict;
    use warnings;
    ...
    my $a = $p->[0];    ## Gives no warnings!!
    my $q = undef;
    my $b = ${$q}[0];   ## Gives no warnings!!
    
  41. or download this
    ...
    print("$p\n");  # ARRAY(0x1abefa0)
    print("$q\n");  # ARRAY(0x1abf054)
    
  42. or download this
    # Create some subroutines to find:
    sub PACKAGEA::PACKAGEB::test {}
    ...
    
    print(join(', ', check_for_sub('test')), $/);
    # Prints "main, PACKAGEA::PACKAGEB, PACKAGED"
    
  43. or download this
    # Create some packages for testing:
    $PACKAGEA::ANYVAR = 1;
    ...
    PACKAGEA exists
    PACKAGEA::PACKAGEB exists
    PACKAGEC doesn't exist
    
  44. or download this
    # Create some packages for testing:
    $PACKAGEA::ANYVAR = 1;
    ...
    IO
    CORE
    main
    
  45. or download this
    $color = substr($color, -6);
    $color .= '0' x length(6-$color);
    $color =~ s/[^0-9A-Fa-f]/0/g;
    $color = hex($color);
    
  46. or download this
    // K&R C:
    char string[6] = "hello";  // Initializes string[] to "hello\0".
    ...
    
    a1 = "Greetings";  // ERROR
    a2 = "Greetings";  // OK
    

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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-19 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found