Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

GotToBTru

by GotToBTru (Prior)
on Jun 15, 2010 at 13:25 UTC ( #844862=user: print w/replies, xml ) Need Help??

Learned Perl

around 2001 when an EDI trading partner insisted on using FTP instead of a VAN. I needed a quick way to send and receive that could be embedded in a scheduler, and I knew "Perl does that." 4 hours later, we were up and running.

I use Perl to examine data files and system logs, to produce automated emails and database updates, to perform file transformations, and to perform automated file transfers (moves and/or ftp).

The name GotToBTru is from the title of a song by Christian singer/songwriter Steven Curtis Chapman, and marked his first foray into something approximating rap music. He uses the lyrics to poke fun at himself (and also his listeners). Two things I like: despite his "superstar" status he doesn't take himself too seriously, and the reminder in the lyrics ("gotta be livin' what I say I believe") that nobody will believe my words unless my behavior backs them up.

That Signature...

"But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us." Romans 5:8 (NASB)

This verse is intended to grab your attention because God acted unlike how people think he would act, how they think they should act. Most people think that to please God, to get him to care about you, you have to clean up your act first. You have to stop doing all that wrong stuff, start doing things right. And we think that about other people, too: I won't forgive them until they show me they're sorry.

But God didn't do it that way. He didn't wait for you to become good before he acted. And good thing, too; none of us would have sought him out on our own. The link below is an excellent explanation of why we are how we are, why we know we should be better but somehow can't make ourselves be, and the solution to that problem.

The Gospel

Or see this for a shorter version.

Or read this for an excellent treatise on the rationality of the Christian world view.

Quotes

Do not look at laser with remaining eye - warning sign in physics lab

An educated man has been defined as one who can entertain himself, one who can entertain another, and one who can entertain a new idea. - Commander Edward Whitehead

Do not regard what you do only as preparation for doing the same thing more fully or better at some later time. Nothing is ever done twice. There is no next time. - General George Patton

The plural of 'anecdote' is not 'data'.

Social Media

LinkedIn Profile

Twitter

Blog (infrequent updates!)

Other interests:

Amateur (ham) radio (callsign AE0Z), Toastmasters(ACB,ALB), vocal and instrumental music, Christian apologetics, Torah observance for Christians

Picture

is a Yaesu FT-101ZD ham radio transceiver. This was the last of several models of this radio made in the 1970s and 80s. Note the stylish LCD display. My own (not pictured) is almost as old as Linux.

Well, that about sums it up for evolution:

Life has never been observed to come from non-life.

There is no known observable process by which new genetic information can be added to the genetic code of an organism.

And, some of the reasons to investigate Intelligent Design seriously:

Three Scientific Evidences that point to a designed universe by Dr. Walter L. Bradley

Cute

Des‎crip‎tionStringLooks Like
Music♫
TM™
&&&
<&lt;<
>&gt;>
[&#91;[
]&#93;]

Useful Links:

PerlMonks:Last Hour of CBFullpage ChatLinking Shortcuts
Approval LogMarkup in the MonasteryWriteup Formatting Tips
Levels of MonksKeyboard ShortcutsHow do I post a question effectively?
Better Programming:DBI RecipesBasic Debugging ChecklistReal Life Perl Exercises
Regex TesterData Structures CookbookReferences quick reference
Module StyleExcellent Hash Referenceunary file test operators
More on references

Posts I'm proud of:

Although, if I take too much (any really) pride in my posts here, I need only notice that there is a strong inverse correlation between rating and how much I type!

Sainthood!

679th Saint in the Book December 10th, 2014.

Fun Milestones

  • 08/31/15 - You have 1248 points until level 16 - Parson.
  • 03/22/16 - You have 1277 points until level 17 - Prior. (digits total 17)
  • 12/20/16 - You have 2646 points until level 18 - Monsignor.
  • 12/20/16 - You have 2637 points until level 18 - Monsignor. (twice in one day)
  • 03/07/17 - You have 2277 points until level 18 - Monsignor.
  • 06/14/17 - You have 1908 points until level 18 - Monsignor.
  • 07/20/17 - You have 1881 points until level 18 - Monsignor. (coolest so far)
  • 09/20/17 - You have 1800 points until level 18 - Monsignor.

Codes

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d-- s:+ a+ C++$ ULA$ P++$ L++>$ !E--- W++ !N !o !K--
w+ !O !M V+>$ PS- PE !Y PGP>$ t+ !5 !X !R tv b++ DI++++ D+
G-- e++ h---- r+++ y?
------END GEEK CODE BLOCK------

Style Code
I2Osi0S<+>++<gt>B0L1C2P0N>R1vl(en)c1a1p(0)r1d0Hsw main-sub


Posts by GotToBTru
Dunning-Kruger Meets Bulwer-Lytton in Perl Poetry
3 direct replies — Read more / Contribute
by GotToBTru
on Aug 12, 2014 at 01:01

    In the writing of poetry, worthy of tribute
    The most crucialistic part is the words in the poem.
    Sure, rhyme, rhythm, meter, these all contribute
    But if you make lousy word choices, people are going to read it and say "Who wrote this trash?" and then somebody says "GotToBTru" and then somebody says "Who's that?" and out of embarrassment they say "Don't know 'im."

    Does Perl Monks have an official Poet Laureate?
    We've got a section here for him, ready and warmed up.
    Meanwhile, rank and file monks fill in with haiku and couplet
    Waiting for a real class act to finally show up.

    That's not me, I'm not a skilled nor prolific Perl Poetry contributor.
    I much prefer coding, I'm not ashamed to admit it.
    So it works out not to be much of a non sequitur
    To say "GotToBTru. Your day job - don't quit it."

    1 Peter 4:10
File test in grep not excluding current directory in Seekers of Perl Wisdom
4 direct replies — Read more / Contribute
by GotToBTru
on Jul 01, 2014 at 09:22

    I am not sure if it is File::Find or grep that is responsible for the behavior I see.

    use strict; use warnings; use File::Find; my $dir='/home/edi/wlsedi/howard/temp'; find({preprocess => sub { return grep { -M $_ < 1 } @_ }, wanted => sub { printf "%s\n",$_ if (-f $_) } }, $dir);

    Output(as expected):

    file1 file2 file3

    I would rather have the directory case handled in preprocess than wanted.

    use strict; use warnings; use File::Find; my $dir='/home/edi/wlsedi/data_backup/univfiledrop'; find({preprocess => sub { return grep { -f $_ && -M $_ < 1 } @_ }, wanted => sub { printf "%s\n",$_ } }, $dir);

    Output:

    . file1 file2 file3

    Why is . included?

    Update

    File::Find calls the wanted function with the directory name before it performs the readdir() on the directory. The preprocess routine is not called for this invocation.

    use strict; use warnings; use File::Find; my $p = 0; my $dir='/home/edi/wlsedi/howard/temp'; find({preprocess => sub { printf "p %d %s\n",$p++,$_; return @_ }, wanted => sub { printf "w %d %s\n",$p++,$_ } }, $dir);
    ls -e /home/edi/wlsedi/howard/temp total 0 drwxr-xr-x- 2 wlsedi wlsedi 256 Jul 01 09:33 dirhere -rw-r--r--- 1 wlsedi wlsedi 0 Jul 01 08:14 file1 -rw-r--r--- 1 wlsedi wlsedi 0 Jul 01 08:14 file2 -rw-r--r--- 1 wlsedi wlsedi 0 Jul 01 08:14 file3

    Output:

    w 0 . p 1 . w 2 file1 w 3 file2 w 4 file3 w 5 dirhere p 6 dirhere
    1 Peter 4:10
Storing Experience for Posterity in Cool Uses for Perl
4 direct replies — Read more / Contribute
by GotToBTru
on Jun 12, 2014 at 10:34

    I put the following together to scrape experience, level and writeups off my profile page and store it in a text file on my computer, to record my progress through the Monastery. A scheduled task runs this once a day.

    use strict; use warnings; use LWP::Simple; use URI::URL; my $date=`ECHO %DATE:~10,4%%DATE:~4,2%%DATE:~7,2%`; # YYYYMMDD my $url = url('http://perlmonks.org/?node_id=844862'); my $content = get($url); $content =~ s/\cJ//g; $content =~ s/\cM//g; my ($experience, $level, $posts) = ($content =~ /Experience:\D+(\d+).+ Level:.+([A-Z][a-z]+\s+\(\d+\)).+ Writeups:.+>(\d+)</x); open my $ofh, '>>','perl_xp.dat'; printf $ofh "%d,%d,%d,%s\n",$date,$experience,$posts,$level; close($ofh);

    There is probably a way to do this in Javascript that could be included in the Free Nodelet, but that's beyond my skill level.

    Update

    Improved version here.

    1 Peter 4:10
Debugger Questions - Variable Scope in Seekers of Perl Wisdom
4 direct replies — Read more / Contribute
by GotToBTru
on May 15, 2014 at 18:43

    If I run the following code in the debugger:

    use strict; my $t = 14; blah(); print "$t\n"; sub blah { my $t = 42; print "$t\n"; }

    and I place a watch on $t, it applies to both the main program variable and the subroutine variable, even though they are distinct. When the assignment statement in the subroutine executes, it reports that the value changed from 14 to 42, which is not true. Perl is not confused, the values of the variables stay distinct, but the debugger can't keep the namespaces distinct. Or perhaps it can -- is there a way to tell the debugger I want to watch only the variable in the subroutine?

    Also, if I make calls to modules, variables in my code go out of scope. If I am watching them, the debugger halts twice, once to tell me the variable now has no value, and once again to tell me it has reappeared! Is there a way to avoid these halts?

    Neither of these issues is more than an annoyance, but just in case I'm missing something ...

    Update: simplest solution here.

    1 Peter 4:10
Remove RTF Formatting in Cool Uses for Perl
2 direct replies — Read more / Contribute
by GotToBTru
on Feb 22, 2011 at 14:38
    We have clients sending us (in many ways) documents (in many formats) which we process automatically instead of having somebody key the data in. Applications like this are basically why my group exists at work.

    Latest challenge: file is in Rich Text Format. I don't need to parse it, or convert it into HTML. I just want the data, absent any formatting.

    Here is my end result. The regexes could no doubt be tightened up.

    use strict; use warnings; my ($wholefile,$line); my $outfilename='orderdata.out'; {open INFILE, '<', "orderform.rtf"; local $/; $wholefile=<INFILE>; close(INFILE); $wholefile =~ s/^\s*{.*\n//g; # remove lines starting wi +th braces $wholefile =~ s/\\[\w-]+\b//g; # remove RTF commands $wholefile =~ s/(\n)\s+(\S+)/$1$2/g; # remove extra spaces $wholefile =~ s/([^\\\n]+)\\(\n)/$1$2/g; # get rid of \ at the ends + of lines $wholefile =~ s/\\\n//g; # get rid of lines with a +\ only open OUTFILE,'>',$outfilename or die "Can't open $outfilename!\n"; print OUTFILE $wholefile; close(OUTFILE); }
    Update: applied suggestions to regexes #1, #2
A perl haiku, eh? in Perl Poetry
1 direct reply — Read more / Contribute
by GotToBTru
on Jan 25, 2011 at 17:07
    A perl haiku, eh?
    The Swiss Army Chainsaw makes
    coding a pleasure
Recognize X12 Interchanges in Cool Uses for Perl
2 direct replies — Read more / Contribute
by GotToBTru
on Aug 05, 2010 at 14:47

    The question came up on a list dedicated to EDI (electronic data interchange) about how to recognize EDI data in a file. Interchanges formatted in accordance with ANSI X12 standards are made up of labeled, delimited records called segments.

    A pair of segments form the outermost "envelope" around the data, the ISA and IEA segments. The ISA segment is 106 characters long, including the segment terminator character. The terminator tells you how to break the file into segments and another character, the element delimiter, tells how to break the segments into elements. This last is the 4th character in the ISA segment. These two characters, the segment terminator and element delimiter, are not specified in the standards and companies/industries use a variety of choices.

    Ever since I first learned about Perl I figured it would be ideal for dealing with EDI files. I worked out a regexp for identifying an EDI file by the presence of this fixed length ISA segment. The result is the ability to recognize an X12 file, without knowing ahead of time which delimiter and terminator your trading partner chose, and it delivers them up to you as a side effect of recognition.

    ($elemdelim,$segterm) = ( $contents =~ /ISA(.)..\1.{10}\1..\1.{10}\1..\1.{15}\1..\1.{15}\1.{6}\1. +{4}\1.\1.{5}\1.?.{9}\1.\1.\1.(.)/);

    It is said among X12 experts that the ISA is not fixed length. Element 14 is a 9 digit control number, which could be negative (according to the data type definition of the element but in complete contravention to the practical use of control numbers), in which case the ISA would be 107 characters long. This is silly, in my opinion, but is also easily dealt with using ".?".

    I have also opted to use the . instead of \d or \w. That's just because I can't be bothered to type two characters when one will do.

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 studying the Monastery: (6)
As of 2019-03-19 14:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How do you Carpe diem?





    Results (91 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!