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

Cool Uses for Perl

( #1044=superdoc: print w/ replies, xml ) Need Help??

This section is the place to post your general code offerings.

CUFP's
Create json from command line args
2 direct replies — Read more / Contribute
by teamster_jr
on May 20, 2015 at 10:39
    Not hilariously useful, but quite fun to write ntl.
    #!/usr/bin/perl use strict; use warnings; use Data::Dumper; @ARGV = qw{ --keyed_array_from_multiple_arguments a b --keyed_array_from_multiple_arguments c --keyed_array_from_multiple_arguments 1 --keyed_with_equals=1 --switch --multi.level a --funny_numbers -99.999 --switchable_switch --noswitchable_switch } unless @ARGV; use JSON::XS; use Scalar::Util qw{looks_like_number}; my ( $arguments, $data ); $arguments = join $", @ARGV; $arguments =~ s{ \s* # some space --([\.\w]+) # an argument \s*?=?\s* # some space or = (.*?) # some values \s*(?=--|$) # followed by another argument or end of line }{ my ($opt_name, $values)=($1,$2); for my $opt_value ( $values ? ( split /\s+/, $values ) : $opt_name +=~s/^no// ? JSON::XS::false : JSON::XS::true ) { my $pointer = \$data; for my $opt_key ( split /\./, $opt_name ) { $pointer = \$$poin +ter->{$opt_key} }; $opt_value = ( ref($opt_value) || !looks_like_number($opt_valu +e) ) ? $opt_value : 0 + $opt_value; $$pointer = $$pointer && ! (ref($opt_value) =~/Bool/) ? [ ( re +f($$pointer) eq 'ARRAY' ? @$$pointer : $$pointer ), $opt_value ] : $o +pt_value; } }xeg; print JSON::XS->new->pretty->encode($data)
Get DoB Bounds from Age Range
3 direct replies — Read more / Contribute
by over2sd
on May 07, 2015 at 12:18

    Here's a function I wrote to turn a range of ages into a pair of date-of-birth boundaries for use in database queries (or wherever else a date-of-birth boundary is more useful than an age range). Comments and suggestions for improvement are welcome.

    Updated: prettier variable names, better error handling.

    Updated: Removing use of now()

    =item DoBrangefromAges REFERENCEDATE MINAGE MAXAGE Given a REFERENCEDATE from which to calculate, minimum age MINAGE, and an optional maximum age MAXAGE, this function returns two strings in YYYY-MM-DD format, suitable for use in SQL queries, e.g., 'WHERE ?<dob AND dob<?', using the return values in order as parameters. If no MAXAGE is given, date range is for the year spanning MINAGE only. =cut sub DoBrangefromAges { my ($querydate,$agemin,$agemax,$inclusive) = @_; die "[E] Minimum age omitted in DoBrangefromAges" unless (defined +$agemin and $agemin ne ''); $agemin = int($agemin); $agemax = int($agemin) unless defined $agemax; $agemax = int($agemax); $inclusive = ($inclusive ? $inclusive : 0); my ($maxdob,$mindob) = ($querydate,$querydate); $maxdob->subtract(years => $agemin); $mindob->subtract(years => $agemax + 1); return $mindob->ymd('-'),$maxdob->ymd('-'); }
File Similarity Concept (re [id://1123881])
1 direct reply — Read more / Contribute
by ww
on Apr 21, 2015 at 12:41

    Proof of concept -- sparked by the discussion in Similarity measurement. NB that this is NOT PRODUCTION GRADE CODE nor does it resolve all issues with the loose (aka 'incomplete') spec in the OP)

    #! /usr/bin/perl -w use 5.018; # 1123881a.pl (cf [id=1123881]) # $file1 is used in place of OP's text file1; DATA stands in for text +file 2 # perl 5, version 18, subversion 4 (v5.18.4) built for MSWin32-x86-mul +ti-thread-64int # ... # Binary build 1804 [298913] provided by ActiveState http://www.Active +State.com # Built Mar 19 2015 17:49:00 my (@F1, %F1, @F2, %F2); my $file1 = "Now is the time for the quick red fox to jump over the la +zy brown dog's spooon while all good men run away with the fork and c +ome to the aid of their country"; chomp $file1; @F1 = split / /, $file1; # individual words my $file2 = <DATA>; chomp $file2; @F2 = split / /, $file2; $F1{$_}++ for @F1; # produces hash with key::value p +airs word => count for each word $F2{$_}++ for @F2; say "\n\t --- Ln 25 Printing keys and values for the HASHES, \%F1 and +\%F2\n\t\t ...and creating ARRAYS \@F1combined and \@F2combined."; my (@F1combined, @F2combined); # while ( my ($key, $value) = each(%F1) ) { print "$key => $value\n"; push @F1combined, ($key . ' => ' . $value); } say "\n\t --- \%F2, next: ---"; while ( my ($key, $value) = each(%F2) ) { print "$key => $value\n"; push @F2combined, ($key . ' => ' . $value); } my @sort_arr1 = sort {fc($a) cmp fc($b)} @F1combined; # fc to norma +lize my @sort_arr2 = sort {fc($a) cmp fc($b)} @F2combined; my $entry; # a complete element of an array, @sor +t_arr1 in this case. See Ln 54 my $counter = qr/ => \d+/; # the part of of the element we'll exc +lude in Ln 22-23 (so can match words w/variant counts) my $word; # search term for the word only, less +the fat arrow and counter; see Ln 22-23 my $match_count = 0; my $mismatch=0; my $len1 = $#sort_arr1; # used to determine the terminal state + of the loop at Ln 50 my $len2 = $#sort_arr2; my $item_count = ($len1 > $len2) ? ($len1+1) : ($len2+1); # Longer o +f the two arrays (files) ... say "\t\t \$item_count: $item_count"; # which ca +uses "uninit" warnings at Ln 55 et seq. my $i; for ( $i=0; $i<($item_count); $i++) { my $entry = $sort_arr1[$i]; chomp $entry; say ">> Ln 56 \$i: $i |$entry| "; # can be used for DEBUG if ( $entry =~ /(\w+)$counter/i ) { $word = $1; } else { next; } if ( grep {/$word/} @sort_arr2 ) { say "\t found |$word| in both arrays (files) \n"; $match_count++; } else { say "\t didn't match entry, |$entry| \n"; $mismatch++; } } say "\n\t \$match_count: $match_count"; say "\t \$mismatch: $mismatch"; my $element_total = $match_count+$mismatch; say "\n\t SLOPPY SPEC: among other issues, does not treat cases where +the number of instances of a word in one file \t is different than the number of instances in the second file as a m +ismatch (eg. if the word is in both, even \t though in differing quanties, it's treated as a match."; say "\t No allowance made for use with arrays having different numbers + of elements (variance produces 'uninitialized' warnings).\n"; say "\n\t Here's one measure of SIMILARITY (using matchs/total element +s evaled): " . $match_count/$item_count; say "\n\t Another uses the total of matches and mismatches as the divi +sor: " . $match_count/$element_total; say "\n\t Magnitude of DIS-similarty (using the ratio of mismatches/ma +tches) : " . $mismatch/$match_count; say "\n\t By the same sloppy spec, but using mismatch/elements_in_firs +t_array): ". $mismatch/($#sort_arr1 + 1); __DATA__ now is the time for all good men to come to the aid of their country w +hile the quick red fox jumps over the lazy brown dog's back and the f +ork runs away with the spoon

    Output for review is in the readmore

    Hope you find this interesting.


    Spirit of the Monastery

    ++$anecdote ne $data

file age in seconds using M file test
2 direct replies — Read more / Contribute
by FreeBeerReekingMonk
on Apr 15, 2015 at 19:17

    Sometimes you just want to know the age of a file in seconds:

    perl -e 'print (int((-M shift)*60*60*24)||1)' script_file

    The ||1 is to ensure a positive number. You can leave it out. To get the file age in minutes:
    perl -e 'print (int((-M shift)*60*24))' script_file

510 Concurrent/Simultaneous SQL Processes running on Windows O/S Laptop
3 direct replies — Read more / Contribute
by erichansen1836
on Apr 15, 2015 at 11:29

    This script launches 510 simultaneous/concurrent MS-Access database SQL queries, which the database Jet Engine

    can handle just fine with increased Threads configured to 510, default is 3. The calling script launches

    the 510 instances, then immediately exits without waiting for them to complete. If you run this from a command

    prompt, and open Windows Task Manager, you can watch the concurrent processing occuring since I have prints to the

    screen going on. CPU usage will hit 100%, and my RAM memory usage hit a high of 83% for a split second, then fell

    back down rapidly. I have a single Intel Celeron processor 2.2GHz, and 3-GIG RAM on my WIndows 7 Home Premium

    Laptop. The database hit, contains a table of Bible book names: Genesis thru Revelation (66 books).

    510 output files are created witht the SQL report output. I used a File Compare routine to verify all the same output.

    This reporting process produces reliable SQL output every time. Way to go Jet Engine!

    CALLING SCRIPT

    use Win32; use Win32::Process; $PWD=Win32::GetCwd(); for ($i=1; $i<=510; $i++) { Win32::Process::Create($POBJ,"$PWD\\RptUtl.exe","RptUtl $i",0,DETACH +ED_PROCESS,"."); } exit;

    #######################################################################################################################

    CALLED SCRIPT i.e. RptUtl.exe <-- compiled RptUtl.pl

    use Win32::ODBC; use Win32; use IO::Handle; $i=$ARGV[0]; #-- called from another Perl script that launches 1 to +510 Windows O/S "detached" background processes. $PWD=Win32::GetCwd(); $outfile="$PWD\\BibleBooks_$i.txt"; open(OUT,"> $outfile"); OUT->autoflush(1); $USR=Win32::LoginName(); $NODE=Win32::NodeName(); print OUT "Working Directory=\n $PWD\n User=$USR Node=$NODE\n\n"; $FILEDSN="FILEDSN=$PWD\\Bible.dsn; PWD=xYz"; $db = new Win32::ODBC($FILEDSN); if (! $db) { $error = Win32::ODBC::Error(); print OUT "$error\n"; die; } $ret=$db->Sql("SELECT * FROM BibleBook"); if ($ret) { $error = Win32::ODBC::Error(); print OUT "$error\n"; die; } while ($db->FetchRow()) { my(%data) = $db->DataHash(); print OUT $data{'bk'} . " " . $data{'name'} . " " . $data{'shor +t_name'} . "\n"; print $data{'bk'} . " " . $data{'name'} . " " . $data{'short_na +me'} . "\n"; } print OUT "\nGood bye.\n"; exit; END { if ($db) { $db->Close(); undef $db; } close(OUT); }

    CONTENTS of ODBC FILEDSN Bible.dsn which is referenced in the above code

    [ODBC]

    Threads=512

    Driver=Microsoft Access Driver (*.mdb)

    DBQ=.\Bible.mdb

    Update: Goodbye

Non-Formula based Text Encoding - with Compression
3 direct replies — Read more / Contribute
by erichansen1836
on Apr 15, 2015 at 10:15

    #################################################################################################

    #-- ENCODING with COMPRESSION (non-FORMULA based).

    #--

    #-- Create 242,234 unique codes, 1-3 characters in length, from the characters {a-zA-Z0-9}.

    #-- 62 (1 char codes) + 3844 (2 char codes) + 238,328 (3 char codes) = 242,234 unique codes.

    #-- (Somewhat like MIMEbase64 encoding, but my encoding is non-formula based.)

    #--

    #-- The unique codes can be mapped to a unique list of words(+ punctuation) occuring between

    #-- whitespace within a text document. The text document can be rewritten in encoded/compressed

    #-- fashion this way, by mapping words to codes, then decoded at a later time using a persistent Perl SDBM database tied hash

    #-- table holding the word-to-code mappings for a particular text document.

    #-- There are a number of ways to do the word-to-code mappings, to add randomness to the

    #-- assignments. That fact makes this encoding scheme undecipherable.

    #-- There are just too many combinations of how 242,234 codes can be

    #-- mapped to the infinite number of words(+ punctuation) occuring between whitespace within

    #-- a text document (or database table), no 2 text documents having the same words(+punctuation) mapped to the same

    #-- codes, after random assignment of codes is introduced.

    #-- Seeding is the word for introducing randomness into the word-to-code assignment.

    #--

    #-- That said, there really is no need for secrecy when discussing this encoding strategy,

    #-- in general terms, like I have done here, since this is not formula based encoding/decoding.

    #-- BELOW:

    #-- Perl code example to create an output file of the 242,234 unique codes, 1-3 chars long.

    #-- These codes can be read into a program hash table (of key/value pairs) to assign unique

    #-- words in a text document to unique codes 1-3 chars long. Random seeding can be introduced,

    #-- plus sorting of the unique codes and/or unique words, to create an infinite number of

    #-- possible word-to-code mapping combinations each time a different text document is encoded.

    #-- The unique words in any 2 text documents never being mapped to the same codes.

    #################################################################################################

    #-- GIVE IT A TRY! SEND A FRIEND AN ENCODED TEXT EMAIL (or ATTACHMENT) TO TRY TO DECIPHER.

    #-- Secretly tell your boss just what you think of him/her. @#%%*@!@#

    #-- Tell that person you admire from afar, what you think of him/her. X0X0X0X

    #-- Freak out your high school English teacher or college professor by turning in your essay

    #-- in encoded form, and act like it's a normal thing he/she should be able to read. Duh! You're a teacher, can't you decode that?

    #-- Tell them you didn't want another student copying your work (a borrowed work at that).

    #-- Do the work of a monk and encode the Bible for posterity safe keeping.

    #-- Send the IRS your annual Income Tax Filing encoded (don't cheat !!!).

    #-- Become an informant for the FBI or CIA. Become a private investigator. etc.

    #################################################################################################

    use IO::Handle;

    $outfile=".\\wordcodes.txt";
    open(OUT,"> $outfile");
    OUT->autoflush(1);

    @array1=split(/ */,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');

    @array2=@array1;    @array3=@array1;

    foreach $i (@array1) {
       print OUT "$i\n";
       foreach $j (@array2) {
           print OUT "$i$j\n";  
           foreach $k (@array3) {
              print OUT "$i$j$k\n";
           }
       }
    }
    close(OUT);
    exit;
simple Perl script template
3 direct replies — Read more / Contribute
by Dumu
on Apr 09, 2015 at 06:47

    I wrote this script because I just wanted to automate typing two lines of Perl every time I wrote a small test-case script.

    This is dead simple and doesn't really count as 'cool'. However, in the words of the Greek poet Callimachus and E.F. Shumacher, "small is beautiful".

    The script simply prints its own top two lines into every new file specified on the command line, unless the file already exists.

    Any and all feedback will be welcomed.

    #!/usr/bin/env perl use Modern::Perl; while (<@ARGV>) { my $fname = $_; unless (-e $fname) { open my $fh, '>', $fname; say $fh "#!/usr/bin/env perl"; say $fh "use Modern::Perl;\n\n"; say STDOUT "created $fname"; } else { say STDOUT "*** didn't overwrite $fname"; } }
Number functions I have lying around
2 direct replies — Read more / Contribute
by Lady_Aleena
on Mar 30, 2015 at 20:30

    I was going through old scripts I had lying around and decided to clean them up a bit. I don't remember why I wrote them or what I am going to do with them. I think they are lukewarm uses for perl, and I probably reinvented the wheel on some of them. Instead of them just lying around my hard drive collecting dust, I share them with you, kind reader. Do with them what you will.

    The first function lists primes, the second two functions list fractions, the last few are about Roman numerals. I lumped them together in a module called Numbers because I ran out of imagination.

    Welcome to my sandbox.

    If you want to see a Roman numeral (MDCCCMVCXXVII) with the overline, go to your display settings and set up the overline class in your style sheet as follows...

    .overline { text-decoration: overline; }
    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Binary DeBruijn sequences.
No replies — Read more | Post response
by BrowserUk
on Mar 30, 2015 at 13:55
    yamātārājabhānasalagam

    I needed a binary (alphabet 0|1) DeBruijn sequence, and found a simple rule for producing one (see the comments).

    I first coded it using strings of '0' and '1' characters and a hash to detect words already included.

    Very quick to code, but using one byte per bit, and a hash, the size rapidly chewed through gobs of memory, long before I reached my target of 31-bit words.

    #! perl -slw use strict; ### Prefer Ones: ### Write n zeros. ### Then, always write a one unless it would cause the repetition of a +n n-length string; ### In which case, write a zero. our $N //= 4; my $seq = '0' x $N; my %seen = ( $seq => 1 ); for( $N .. 2**$N ) { $seq .= ( not exists $seen{ substr( $seq, -( $N-1 ) ) . '1' } ) ? +'1' : '0'; ++$seen{ substr( $seq, -$N ) }; } $seq .= substr $seq, 0, $N-1; print length $seq; <STDIN>; my $re = '(.)(?=(' . '.'x($N-1) . '))'; print $1 . $2 while $seq =~ m[$re]g;

    So then I coded another version that used vec to produce the sequence directly into bits; and another bitvector to track the words seen.

    This was much tricker to code -- despite the apparent simplicity of the code -- and goes much higher, using a mere faction of the memory, but unfortunately stops before my target because vec (as of the version of Perl I'm using) still treats its second argument as a signed, 32-bit integer despite that a) negative offsets make no sense; b) I'm using a 64-bit version of Perl :(

    (If you try it with -N=7 or greater, I strongly recommend redirecting the output, or disabling it, because watching 100s or 1000s of 0s & 1s scroll up the screen is a very boring occupation :)

    #! perl -slw use strict; ### Prefer Ones: ### Write n zeros. ### Then, always write a one unless it would cause the repetition of a +n n-length string; ### In which case, write a zero. our $N //= 4; my $t1 = "b${ \(2**$N+$N-1) }"; my $seen = ''; my $mask1 = ( 1<<$N )-1; my $seq = pack 'Q*', (0) x 100; my $val = 0; for( $N .. 2**$N+$N-1 ) { ## if N=5; 5 .. 36; if N=6 +, 6 .. 64+6-1 = 69; $val = ( $val << 1 ) & $mask1; vec( $seen, $val | 1, 1 ) or do{ $val |= 1; vec( $seq, $_, 1 ) = 1 +; }; vec( $seen, $val , 1 ) = 1; } print unpack $t1, $seq;

    Note: both the above versions produce the 2N+N-1 bit complete sequence, rather than the 2N sequence that is shown in the Wikipedia page which only become complete once you 'wrap them around'.

    Ultimately, I ended up moving to C to achieve my target, which even more tricky (damn, I miss vec in C), but it eventually allowed me to produce the 1/4GB binary sequence I was after.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
"Spritz" crypto algorithm
No replies — Read more | Post response
by RonW
on Mar 24, 2015 at 16:41

    For testing purposes, I implemented Rivist's new crypto algorithm in Perl. It is a proposed replacement for his (once very popular) RC4 algorithm. Thought there might be some curiosity value to it.

Distribute the leftovers
No replies — Read more | Post response
by GotToBTru
on Mar 20, 2015 at 12:46

    We get the quantity of a product shipped from the database, and a list of individual carton labels from an external file. The actual contents of each carton are unknown. Working assumption would be qty per carton = shipped qty / carton count. Easy enough. But what if the division doesn't come out clean?

    use POSIX qw/ceil/; ... $sq = $shipped_quantity; $cc = $carton_count; foreach $label(@label_list) { if ($cc == 0) { print "Qty per carton math error"; next OUTER; } $per_container = ceil($sq/$cc); $sq -= $per_container; $cc -= 1; ... }

    If shipped quantity is 8 and carton count is 5, first 3 cartons will have 2 each, last 2 have 1.

    Yeah, almost too simple to mention. But this came up today, and I remember little code bits like this better when I write them down somewhere.

    Update: s/box/carton/

    Dum Spiro Spero
ppi-outline.pl -- from perl source generate Main logic of this script (summary/abstract/outline)
1 direct reply — Read more / Contribute
by Anonymous Monk
on Mar 13, 2015 at 04:03
Extract names and email addresses from a maildir folder
No replies — Read more | Post response
by peterr
on Mar 11, 2015 at 04:25

    Had a lot of help from Mark Overmeer with this one ..

    #!/usr/bin/perl # # Name: multipart-mo.pl # # Extract names and email addresses from a maildir folder # # - Also displays the number of messages (files) found and the numb +er of parts in each message # - Displays structure of each message and then outputs the names a +nd email addresses # - Where the name/email address is found in the 'body' part of a m +essage (i.e NOT in From:, To:, Cc: etc,etc), # then usually only the email address will be returmed # # This script has been adapted from multipart.pl , which is part of +the Mail::Box module , vers 2.118, # by Mark Overmeer (http://http://search.cpan.org/dist/Mail-Box/ ) # # This code can be used and modified without restriction. # # Usage: perl multipart-mo.pl Smith\,\ Bill\ \&\ Nancy/ (maild +ir folder name) # use warnings; use strict; use lib '..', '.'; use Mail::Box::Manager; sub emails_from_body($); # # Get the command line arguments. # die "Usage: $0 folderfile\n" unless @ARGV==1; my $foldername = shift @ARGV; # # Open the folder # my $mgr = Mail::Box::Manager->new; my $folder = $mgr->open($foldername, access => 'r') or die "Cannot open $foldername: $!\n"; # # List all messages in this folder. # print "Mail folder $foldername contains ", $folder->nrMessages, " mess +ages:\n"; my %emails; foreach my $message ($folder->messages) { my @parts = ($message, $message->parts('RECURSE')); print $message->seqnr, ' has '.@parts." parts\n"; $message->printStructure; foreach my $part (@parts) { foreach my $fieldname (qw/To Cc Bcc From Reply-To Sender/) { my $field = $part->study($fieldname) or next; $emails{$_}++ for $field->addresses; } my $ct = $part->contentType || 'text/plain'; $ct eq 'text/plain' || $ct eq 'text/html' or next; $emails{$_}++ for emails_from_body $part->body->decoded; } } print "$_\n" for sort keys %emails; $folder->close; exit 0; ### HELPERS sub emails_from_body($) { $_[0] =~ /([-\w.]+@([a-z0-9][a-z-0-9]+\.)+[a-z]{2,})/gi; }

    It works. :)

Convert Doxygen to POD
No replies — Read more | Post response
by RonW
on Mar 06, 2015 at 19:01

    This is a work in progress, but usable.

    Because, at work, my team and I use Doxygen to aid in producing code documentation, and not being satisfied with the available preprocessors for handling Perl in Doxygen, I considered improving one of them or maybe writing a new one. Then it occurred to me that converting Doxygen markup in to POD might make more sense.

    For my team and I, Doxygen has been very handy in documenting our code. Partly because the document source is right there with the code source. And because it helps us avoid violating the "Don't Repeat Yourself (DRY)" rule. This "filter" brings some of Doxygen's features to documenting Perl.

    Currently, this "filter" only generates POD from Doxygen-style markup. Any POD markup is passed through as-is. A future version, possibly based on PPI, might include an enhanced POD markup to provide these features.

    Again, this is a work in progress. I know I need to improve the structure. Also, it is not yet a module. There are also quirks I haven't put time in to working out.

    Update: Fixed bugs in handling of $VERSION and in handling of parameters.

EEPROM on i2c Real Time Clock Modules
1 direct reply — Read more / Contribute
by anita2R
on Mar 03, 2015 at 18:16

    Recently I bought a Real Time Clock module to attach to a Raspberry Pi using i2c. Getting the RTC up and running was pretty straight forward, but then I noticed that the board included an Atmel AT24C32 eeprom.

    Despite extensive searches I could not find information on accessing the eeprom. I already had the HiPi::BCM2835::I2C module installed, but again the available documentation was limited, but in the end I produced two scripts for reading and writing to the eeprom, using its sequential 32 byte read and write function. This allows sequential reads or writes for up to 32 bytes from a page address.

    As a 'less than Perl Monks novice' I humbly place the following two scripts here for others who want to use the eeproms on their RTC modules. Any advice on improving my code would be welcome

    Write to eeprom

    The script must be called as root, but permissions are put back to a normal user in the script. The two variables $user and $group need to be entered, and if necessary the eeprom address on the i2c bus should be changed - it is currently 0x57, and is on the i2c-1 bus (change to i2c-0 for rev. 1 Raspberry Pi's)

    The write program requires a start address after the -a parameter (there is no default) and input can be piped to the script, entered as text in quotes after a -t parameter, or put as a path/filename after -t for a text file to be used as source

    Example calls

    Write to eeprom code (improved commenting - thanks to roboticus)

    Read from eeprom

    The script to read from the eeprom is simpler. It requires a start address after the -a parameter (defaults to 0) and a length of data to read after the -l parameter (defaults to 32). Optionally a -o parameter takes a path/filename to receive output. A valid path is required, but if the file is not present it is created. Existing files are appended to. With no -o option the output is to screen, formatted with the eeprom hex addresses, if a -h parameter is included the data is displayed in hex, rather than the default character display.

    Revised Read from eeprom code based on feedback from roboticus

    anita2R


Add your CUFP
Title:
CUFP:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • 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 contemplating the Monastery: (14)
    As of 2015-05-29 20:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      In my home, the TV remote control is ...









      Results (593 votes), past polls