Home
Perl Developer's Journal
 
[Most Recent Entries] [Calendar View] [Friends]

Below are the 20 most recent journal entries recorded in Perl Developer's LiveJournal:

    [ << Previous 20 ]
    Thursday, March 6th, 2008
    4:10 pm
    [jfroebe]
    Has anyone written a perl <=> Yahoo calendar script/app?
    I’ve looked on Yahoo, Google, CPAN and on Perlmonks to no avail. I’m wanting to access my Yahoo Calendar from Perl so I can manipulate it, sync it, etc. So far, I’ve only found commercial or shareware applications that can access the calendar. Has anyone done this or know of a non-perl sdk I can look at to write a perl sdk to do it?


    Current Mood: frustrated
    Friday, November 2nd, 2007
    2:51 pm
    [patrickwonders]
    Idiom question

    So, I have lots of perl code that parses XML to a dom using XML::Simple and then tries to iterate over particular tags. When I inherited this code, there were many loops like this:

        if ( $dom->{'foo'} ) {
    	foreach my $foo ( @{ $dom->{'foo'} } ) {
    	    # blah, blah, blah
    	}
        }
    

    Some daringly omitted the if. But, then along came some XML without the <foo> tag and the cron jobs gacked.

    I find the whole if-wrapper thing to be distracting from the main-line of the code. I've adopted this idiom instead:

        foreach my $foo ( @{ $dom->{'foo'} || [ ] } ) {
    	# blah, blah, blah
        }
    

    ...which is what I wish Perl would do for me anyway when I try to coerce undef to an array context.

    My question is: is this too obscure or arcane? Is this going to confuse people or will they just say... Ah, it's looping over the foo things and just ignore the rest of the line noise?



    Current Mood: curious
    Thursday, August 16th, 2007
    10:15 am
    [chasman]
    Does anyone know how to use the sed command to capture the next line in a file?
    Friday, July 6th, 2007
    11:33 am
    [hjsb]
    Searching the $PATH for a command
    OK, if I want to check a file exists, I use
    if ( -f "~/.bashrc" ) { blah ; }

    But is there a way to do something similar to see if a command exists in the current path? I.e. to check that if I do
    system("my_command");

    It will find the command and run it.
    Ideally, it would also check aliases, functions, etc, but this is not necessary. I could get the filename using a system(which) call, then check that that is executable, but it seems such a long way round. Any ideas?
    Friday, May 18th, 2007
    5:05 pm
    [jfroebe]
    Geek Spotlight: Nicola Worthington

    Every once in a while, I'm going to try to highlight an individual that stands out from the rest. Earlier today I was fortunate enough to be able to sit down, virtually, with Perl developer, Nicola Worthington....

    Read more...



    Current Mood: accomplished
    Thursday, May 10th, 2007
    6:29 pm
    [jfroebe]
    O_DIRECT & O_ASYNC, Linux & Perl

    I've written a C program that creates a 20GB file using O_DIRECT and O_ASYNC correctly. The trick to write to a file using O_DIRECT is that I have to align the buffer with respect to the memory block size.

    When I write a similar program using Perl, I receive the expected "System write error: Invalid argument" as the buffer is not aligned.

    So, my question is: Is it possible, in Perl, to align the buffer?

    #!/usr/bin/perl use strict; use warnings; $|++; use Fcntl qw(:DEFAULT O_ASYNC O_DIRECT); my $FH; sysopen($FH, "./test.dat", O_WRONLY | O_TRUNC | O_CREAT | O_ASYNC | O_DIRECT, 0666); my $BUFFER = "0"x1048576; my $BUFSIZE = 1048576; for (my $i = 0; $i < 20480; $i++) { my $written = syswrite($FH, $BUFFER, $BUFSIZE); die "System write error: $!\n" unless defined $written; }

    Jason L. Froebe

    Don't forget Mother's Day! It's this Sunday so get her some sock yarn.



    Current Mood: frustrated
    Monday, February 26th, 2007
    10:09 am
    [chasman]
    New Perl Programmer
    I found some code online that grabs the size of a file. I have tried to modify that code to put the file size into another file called temp1.txt, but I am having trouble.

    Could someone help? I know this is an easy issue. I am simply not a perl programmer but am striving to learn.

    Thanks!

    The Code:

    #!/usr/bin/perl
    use strict;
    use warnings;
    use File::stat;

    my($caw) = "temp1.txt";
    my $filesize = stat("growth_file")->size;

    #open(VALUES, $filesize);
    #open(VALUES, "temp1.txt");

    # Put filesize into temp1.txt file
    open(FILESIZE, ">$caw");

    print "Size: $filesize\n";

    close(FILESIZE);

    #close(VALUES);

    exit 0;
    1:39 am
    [beshenov]
    uniesc.pl

    Useful thing. Can you suggest/correct something?

    #!/usr/bin/perl -w
    
    use Getopt::Long;
    use utf8;
    use encoding utf8;
    use charnames qw(:full);
    
    GetOptions ( "format=s" => \$format );
    
    # if ($format eq "Source" || !defined($format))
    if ($format eq "Source") { # Escape as \uFFFF
    	foreach my $str (<STDIN>) {
    		utf8::decode($str);
    		foreach (unpack("U*", $str)) {
    			if ($_ > 127) {
    				printf "\\u%04x", $_;
    			}
    			else {
    				printf chr($_);
    			}
    		}
    	}
    }
    
    else {
    	if ($format eq "XML") { # Escape as &#xFFFF; (XML entities)
    		foreach my $str (<STDIN>) {
    			utf8::decode($str);
    			foreach (unpack("U*", $str)) {
    				if ($_ > 127) {
    					printf "&#x%04x;", $_;
    				}
    				else {
    					printf chr($_);
    				}
    			}
    		}
    	}
    
    	else {
    die "uniesc.pl, the Unicode Escaper
    Usage:
    	uniesc.pl --format XML
    for escaping as &#xFFFF;
    or
    	uniesc.pl --format Source
    for escaping as \\uFFFF
    
    Recommended:
    	cat ifile | uniesc.pl [options] > ofile
    ";
    	}
    
    }
    1:35 am
    [beshenov]
    findclones.pl

    Useful thing. Can you suggest/correct something?

    #!/usr/bin/perl -w
    
    use Getopt::Long;
    use File::Find;
    use Digest::MD5;
    GetOptions ( "dir=s" => \$dir );
    
    my %chcksmtbl;
    
    if (not defined $dir) {
    die "findclones.pl, the Clone Finder
    Usage:
    	findclones.pl --dir=/path/to/certain/directory
    ";
    }
    
    sub checksum {
    	my $file = $File::Find::name;
    	if (-f and -r and -e and not -z) {
    	open(FILE, $file) or print "Can't open '$file': $!\n";
    	binmode(FILE);
    		$checksum = Digest::MD5->new->addfile(*FILE)->hexdigest;
    		if (exists $chcksmtbl{$checksum}) {
    			print "$file\tlooks like\t$chcksmtbl{$checksum}\n";
    		}
    		else {
    			$chcksmtbl{$checksum} = $file;
    		}
    	}
    }
    
    find (\&checksum, $dir) or die "Can't open '$dir': $!\n";
    Monday, February 19th, 2007
    3:18 am
    [scriptmafia]
    New good project
    Hello! I would like to provide new project for webmasters and php-developers scriptmafia.org
    You can read rss-translation in LiveJournal [info]scriptmafia
    Wednesday, February 7th, 2007
    12:52 pm
    [jfroebe]
    An easy way to view maintenance logs using a browser
    As part of our regular weekend maintenance for our Sybase database servers, we run many scripts, two of which are: update statistics and reorg/reindex.  In the past, if we wanted to show the output (log) of a maintenance script to someone outside of our group, we had to attach the log to an email and email to the person with instructions to open it using "write" or Microsoft Word and not Notepad because of the way unix/linux and windows handle new lines.  I wanted to get away from this painful ordeal by having the webserver find the logs and display them.  Now we just have to give the url to the person once. Cool

    As we use Apache with mod_perl and Mason quite heavily, I decided the easiest way to do this is to create a component to obtain the list of the log files I'm interested in.  When I click on one of the files, instead of accessing the file semi-directly using a symbolic link to the file, a dhandle is called instead.  The dhandle catches the reorg/SISDBA1.out request, goes and reads the real file and spits it out.  If the file is an archived log (compressed), then we uncompress the file as we read it.

    Adding a new series of log files are easy because the criteria we search for is a prefix in the filename.  Change the prefix in the index.html file, then the new log files are now viewable.  Of course, you will want to either modify the index.html file to handle multiple types of log files or just create another directory (i.e. dbccs) and copy the index.html & dhandler into it.

    Adding a CSS template to this would be a simple matter.  In any case, enjoy!

    Source code

    Current Mood: accomplished
    Wednesday, January 31st, 2007
    6:01 am
    [beshenov]
    Code highlighting

    Hi!

    I am not a Perl geek and I am using patterns and recipes to cook scripts.

    I am trying to do conversion from C / C++ code to the hypertext with style sheets. Actually, it is a code highlighting.

    Script below (sorry for huge code citation) does not work.

    1. It is stupid and complex :-)
    2. It highlights special words inside strings.
    3. It 'eats itself' and replacing <span class="keyword"> to <span <span class="keyword">class</span>="keyword"> in some cases!
    4. It can't highlight word at start of line.
    5. It does not highlights something (why?).

    Help me to correct it.

    Are there good scripts for highlighting code on C / C++ / Java / Perl / Bash / etc.?

    Thanks!

    Read more... )
    Monday, November 6th, 2006
    3:59 pm
    [jfroebe]
    Problem with filtered Mason code & db connection

    Hi,

    In chapter 5 (Advanced Features pgs 82,83) of Embedding Perl in HTML with Mason from O'Reilly, the"a simple SQL select expressed in something like a taglib style" example appears to be straight forward.  It is but it doesn't seem to work too well.

    The premise is that the ".components/sql/select" will filter the chunk of html code
        <&| .components/sql/select, query => 'SELECT name, type FROM sysobjects' &>
    ----> here
            <tr>
                <td>%name</td>
                <td>%type</td>
            </tr>
    ----->to here
         </&>

    The select returns data correctly but the ".components/sql/select" doesn't appear to be printing the code hmmmm....  see the very bottom for the answer... I didn't catch it for awhile but later saw the cause and could have kicked myself.

    Code & Output )

    Current Mood: frustrated
    Monday, July 31st, 2006
    3:51 pm
    [jfroebe]
    mod_perl 2 and CGI::Carp fatalstobrowser

    Hi,

    I know that CGI::Carp and mod_perl 2.0 don't work together. What is being used to produce the same behavior as fatalstobrowser? Meaning, all fatal errors are sent to the browser/user.

    I'm not certain if Mason itself can screw it up. Note that PerlSetVar MasonErrorMode output produces no output at all while PerlSetVar MasonErrorMode fatal writes the fatal errors to the errorlog.



    Current Mood: determined
    3:50 pm
    [jfroebe]
    Mason, mod_perl and DBI
    I'm new to Mason and am having trouble printing a simple html table pulling data from a table on a database.  I know this has to do with scope but there has to be an easier way other than putting the entire dbms call (including printing the table) within a perl code section.
    One thing I have noticed is the apparent lack of any useful information of using Mason with DBI connections.

    This is how you do it:

    code )

    Note, don't forget to uncomment "PerlSetVar MasonErrorMode fatal".  For some reason, no errors were being sent to the browser. :(

    Current Mood: frustrated
    Wednesday, May 10th, 2006
    11:58 am
    [jfroebe]
    How to install DBD::Sybase on Windows using ActiveState Perl
    Assuming that OpenClient is installed:

    Install ActiveState Perl from http://www.activestate.com ; (free)

    -----

    1) Start -> ActiveState Perl -> Perl Package Manager  
        a) install DBI
        b) exit
    2) download latest DBD-Sybase*.zip from http://www.peppler.org/downloads/ActiveState
        a) extract zip file to temporary directory (e.g. c:\test)
        b) Start -> Run -> cmd.exe
            I) cd \test
           II) ppm install DBD-Sybase.ppd
          III) exit

    -----

    That's it :)

    Current Mood: accomplished
    Thursday, January 12th, 2006
    2:49 pm
    [hjsb]
    Difference between system(...) and cp command in the shell
    Apologies if this is a bit of a noob question, but it's confusing the crap out of me:
    If I run this at my bash prompt:
    cp -r "../blah" "./Data/blah"
    it works: in perl it doesn't )
    Tuesday, December 20th, 2005
    11:05 am
    [walkingbear]
    Perl on windows -- serial port access
    I'm trying to write an app that allows me to watch the serial port on a windows machine and respond to various input. In the end this will be a programmable 'device simulator' for my company's dev team so we don't have to code purely to spec for a lot of our hardware interface projects.

    Right now I'm having a hell of a time finding a module that will give me access to the serial port. ppm3 references the Win32-SerialPort module, but apparently it's only available for ia64 architectures.

    Does anyone have a pointer to a 32bit version or some other method of talking to and reading from the serial ports?

    It'd be ideal if it would work with both RS-232 and RS-422 ports.

    Thanks.
    Thursday, September 22nd, 2005
    11:53 am
    [amuzulo]
    the solution to my previous UPC problem
    # ditch UPC Code table
    if ( $ret =~ /UPC Code/ ) {
      $ret =~ s/(.*)<TABLE(.*?)UPC Code(.*?)<\/TABLE>/$1/i;
    }

    I actually had what I thought was the right solution which I posted in the previous thread (and have since deleted), but today I realized it was not working and above is the working regex if anyone is curious. :) Thanks for your help!
    Tuesday, September 20th, 2005
    9:58 am
    [amuzulo]
    regexp help - UPC Code table removal
    I am relatively new to Perl and Regexp and I need to form a regexp that looks to see if a string of HTML has "UPC Code" in it and if so, remove everything within the < table and < /table> tags immediately around it. Some things complicating the issue is that there are other table tags in the HTML string. So, I basically want to find the table with the UPC Code in it and remove it from the string. This is a datafeed we receive from another source, so there is no way to change the way we originally receive the string. Thanks for your help!

    I really need to sit down sometime soon and really learn regexps... Any suggestions on the best way to learn them?
[ << Previous 20 ]
About LiveJournal.com