Hello , I am completely new to Perl , networking and socket programming. In the work , I need to send a UDP packet using perl to another IP Address.. Requirements : 1) I need to send a bunch of values (Ex: 23.43,3435.54,1234.34,356.6) at a time. I cannot send them one by one using for loop. 2) The receiving end only accepts numbers . HERE is the script I wrote
#!/usr/bin/perl #udpclient.pl use IO::Socket; use warnings; use Time::HiRes qw (sleep); my ($socket,$data); #my $in_file_name = $ARGV[0]; $in_file_name='C:\Users\Aryan Sinha\Documents\RecordedData.csv'; open(INFILE,"<",$in_file_name) or die "Not able to open test file $!"; $socket = IO::Socket::INET->new (PeerAddr => '21.22.32.214', PeerPort => 5005, Type => SOCK_DGRAM, Proto => 'udp') or die "ERROR in + Socket Creation : $!\n"; while (<INFILE>) { chomp; if($. != 1) #skip first line { $data=$_; # Data would be in String format my @tempData = split(',', $data); #---------------Description of the problem ------------------- +------- # 1) I have a CSV File of numeric values which I need to send +line by line . # 2) $data has a single line of values in String format . Exam +ple : '2,3.4,2323.23,980.3,235.1' # 3) @tempData is an Numeric array where I stored the values s +pliited from $data . Example : (2,3.4,2323.23,980.3,235.1) # # 4) Now importantly , I need to send the data as a "packet of + Numeric values" at a time using SEND SOCKET command in PERL.The Orde +r of Values should not be changed # #-----------------End of the Description --------------------- +--------- $socket->send($DATA_to_be_SENT); sleep(0.25); } } $socket->close();
Please help me out in this. I am completely new to Perl and Just need this small task to finsih to complete rest of my project based on hradwares working on different platform.

In reply to Send a UDP Packet with bunch of numbers in PERL? by AryanSinha

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.