I'm trying to make something simple that I figured would take like a few minutes in PERL and it's been causing me headaches. I can't figure out why! So I'm hoping someone with wiser eyes might recognize my malfunction. Here's what I'm doing. I'm trying to very SIMPLY take incoming serial data, mark it with the time and date, and then write it to a file. But for some unknown reason, the variable that I capture into can be PRINTED, but when I try to run any function on that variable it dies. Here's the codes I've tried:
#!/usr/bin/perl sysopen(COM, "/dev/ttyS0", O_RDONLY | O_NDELAY | O_NOCTTY) or die "can +'t open /dev/ttyS0: $!"; while(defined ($line=<COM>)) { if (length $line > 1) { #print "read[$line]\n"; system("./parse_smdr", $line); #goto breakout; } } breakout: close COM || die "COM Reader Halted";
I've also tried this:
#!/usr/bin/perl sysopen(COM, "/dev/ttyS0", O_RDONLY | O_NDELAY | O_NOCTTY) or die "can +'t open /dev/ttyS0: $!"; while ($len = sysread(COM, $buf, 16384)) { print "READ[$buf]($len)\n"; if ($len > 10) { system("./parse_smdr", $buf); } } close COM || die "COM Reader Halted";
and even:
#!/usr/bin/perl use Fcntl; use strict; my $line; sysopen(COM, "/dev/ttyS0", O_RDONLY | O_NDELAY | O_NOCTTY) or die "can +'t open /dev/ttyS0: $!"; while($line=<COM>) { if (length $line > 1) { print "read[$line]\n"; system("./parse_smdr", $line); } } close COM || die "COM Reader Halted";
And this doesn't work either....
#!/usr/bin/perl use Fcntl; use strict; my $line; open(COM, "cat /dev/ttyS0 |") or die "can't open /dev/ttyS0: $!"; while($line=<COM>) { if (length $line > 1) { print "read[$line]\n"; system("./parse_smdr", $line); } } close COM || die "COM Reader Halted";
I'm about to lose my mind. Someone help! p.s. and before you ask, the parse script was just pulled out so it didn't make me wonder where my problem was. Here's the code in case you're curious:
#!/usr/bin/perl #print "SMDR Parse Called\n"; foreach $line (@ARGV) { print "Parse[$line]\n"; ($Second, $Minute, $Hour, $Day, $Month, $Year) = localtime(tim +e); #Parse the line by column $type = substr $line,0,4; $dest = substr $line,4,6; $trunk = substr $line,10,6; $src = substr $line,16,20; $dialed = substr $line,32,9; $time = substr $line,45,5; $duration = substr $line,51,8; #print "$Hour:$Minute:$Second,"; #print "$type,$dest,$trunk,$src,$dialed,$time,$duration\n"; open(OUT,">>/home/public/SMDR/smdr$Year$month$day.pbx"); print OUT "$Hour:$Minute:$Second,$type,$dest,$trunk,$src,$dial +ed,$time,$duration\n"; close(OUT); }

Edit by BazB: add readmore tags


In reply to Wierd File pipe problem... by bferlin

Title:
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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.