johan_paz has asked for the wisdom of the Perl Monks concerning the following question:

OK, The gps unit is connected to "/dev/ttyS1" so if i do a "cat /dev/ttyS1" the rusult is:
$PGRME,4.4,M,8.0,M,9.2,M*2D
$GPGLL,5744.022,N,01201.062,E,231149,A*22
$PGRMZ,-128,f,3*3D
............
And i want to save it to "$gpsdata" whit  <STDIN>
If i do a "cat /dev/ttyS1 |./string.pl" with string.pl:
!#/usr/bin/perl $gpsdata = <STDIN>; system("echo $gpsdata");
gives result:
,4.4,M,8.0,M,9.2,M*2D
Broke pipe

Thanks / Johan
( I have tried to grep it before piping it to the perl script,
"cat /dev/ttyS1 |grep ´$GPGLL´ gives me nice lines like:
$GPGLL,5744.022,N,01201.062,E,231149,A*22
but when i do
"cat /dev/ttyS1 |grep ´$PGPLL´ >/tmp/cordinates.txt
it dosen´t write anything in that file. )

Replies are listed 'Best First'.
Re: A strib that begins whit $ (more)
by rchiav (Deacon) on Apr 25, 2001 at 03:40 UTC
    This isn't a perl issue.. it's a shell issue. You need to quote your string like so..

    system("echo '$gpsdata'");
    or you could not envoke the shell and just use print. Unless you have a really good reason to invoke a system call, print is a much better option.

    Rich

    update: changed the var from $_ to $gpsdata

      Alternatively, you can prevent system() from expanding shell metacharacters by using the multi-argument form of system().   system("echo", $_); This oft-overlooked system() behavior is explained in perlfunc.

Re: A strib that begins whit $ (more)
by MeowChow (Vicar) on Apr 25, 2001 at 04:15 UTC
    whit the strib are you saying?
      sorry, too many keybords/screens/hands at the same time ;)