Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8618021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:00:42+00:00 2026-06-12T06:00:42+00:00

I wrote a perl program which send the updated data from a file to

  • 0

I wrote a perl program which send the updated data from a file to remote server periodically. But now i want it to read it from differnt files and send the updated data such that the reciever should know how to seperate the data from the mixed data. Do i just need to put some kind of delimiter? Is there any standards already there for such things?

#############
#Change parameters
############
$PeerAddr='192.168.0.7';
$PeerPort='7070';
##############
# Import packages
##############
use Text::Diff;
use IO::Socket;
#############
# Define global variables
#############
$lineCount=0;
$loopCount=0;
our $stats2 = 0;
for($count = 0; $count <= 10000; $count++){
        my $data_dir="archive/otat/*dat";
        my $data_file= `ls -t $data_dir | head -1`;
        chomp($changed_data_file);
        print "old data_file is $changed_data_file \n";
        chomp($data_file);
        if($data_file ne $changed_data_file){
                $lineCount2=0;
                $changed_data_file=$data_file;
                print ("String:$data_file :$changed_data_file  are not equal\n");
                }
        while(defined($data_file)){
                print "$data_file \n";
                open (DAT,$data_file) || die("Could not open file! $!");
                @iofile = <DAT>;
                $lineCount = @iofile;
                splice(@diffLines);
                print "printing: $lineCount\n";
                print "printing 2: $lineCount2 \n";
                chomp $lineCount;
                chomp $lineCount2;
                if($lineCount != $lineCount2){
                        $j=0;
                        for($i=$lineCount2;$i <= $lineCount; $i++){
                        $diffLines[$j] = $iofile[$i];
                                $j++;
                }
                        $num=@diffLines;
                        print "count of diff lines:$num\n";
                        $lineCount2 = $lineCount;
                        $loopCount=0;
                }
                if($loopCount>2){
                        $loopCount=0;
                        print "Look for recent file \n";
                        last;
                }
                $loopCount++;
                sleep(5);
############################
                &socket_con(@diffLines);
        }

}
#### Methods/Functions
sub socket_con {
        if ($sock== 0){
                $sock = new IO::Socket::INET (
                                                        PeerAddr => $PeerAddr,
                                                        PeerPort => $PeerPort,
                                                        Proto => 'tcp'
                                                        );
                die "Could not create socket: $!\n" unless $sock;
        }
        print $sock @_;
#close($sock);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:00:43+00:00Added an answer on June 12, 2026 at 6:00 am

    I’ve used JSON a lot with good results http://metacpan.org/pod/JSON You can store your data in a hash, serialize it, send the text to the client and have it turn the string back into a Perl hash for easy use. For example:

    # on the server
    use JSON;
    ...
    # store changed lines in a hash
    $diffLines->{$data_file}[$j]=$io_file[$i];
    ...
    # Serialize the hash reference into a string which you then send to the client
    $diffLinesSerialized = encode_json $diffLines;
    
    # on the clinet
    use JSON;
    ...
    # convert received data from serialized string into hash
    $diffLines = decode_json $diffLinesSerialized;
    # $diffLines is now a has reference which can be accessed like normal
    foreach my $data_file (keys %$diffLines) {
      foreach my $line (@{$diffLines->{$data_file}}) {
        ...
      }
    }
    

    All this being said, as much as I don’t really like XML from a programming perspective, it is a prevalent standard for this kind of thing. If this is just a specialized, internal tool that won’t grow into something larger it probably doesn’t matter, but if you think this could turn into a more general service, say for non-perl clients, it would be good to consider XML as an option. Programming from a service-oriented perspective can make it easier to grow things down the road.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a Perl program to capture a live data stream from a tail
I wrote the following regex in perl and now i want to write it
I wrote a Perl program which forks and calls a background program in the
We have a Perl program to validate XML which is invoked from a Java
I wrote a perl script a while ago which logged into my online banking
I am trying to write a program wit Perl which should returns the frequency
I have a perl script (or any executable) E which will take a file
I'm having issues with Unicode characters in Perl. When I receive data in from
I want to write a Perl code that ends the process of another program
I wrote a MATLAB script with gui which I also want to let my-coworkers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.