Sponsored Content
Top Forums Shell Programming and Scripting Need help in parsing an input in perl Post 302757197 by balajesuri on Thursday 17th of January 2013 07:30:27 AM
Old 01-17-2013
Code:
#! /usr/bin/perl -w
use strict;

sub getListenerName {
    my $port = shift;
    my @a = ();
    
    open F, "< file";
    while (<F>) {
        chomp;
        if (/([^ ]*).+?$port/) {
            $a[0] = "TRUE";
            $a[1] = $1;
            last;
        }
        else {
            $a[0] = "FALSE";
            $a[1] = "null";
        }
    }
    close F;
    return @a;
}

my @x = &getListenerName (6712);
print "@x\n";

This User Gave Thanks to balajesuri For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing input paramter in a script

Hi folks I am having a little trouble in parsing a variable read into a ksh script I have a bunch of variables passed into script test.ksh HOST SERVER JOB1 JOB2 JOB3 JOB4 JOB5 What I want to do is read all the $JOB variables ($JOB1, $JOB2, $JOB3) into a variable and then read that variable... (2 Replies)
Discussion started by: Anubhav
2 Replies

2. Shell Programming and Scripting

parsing file2 with input from file1

Sorry dublication with previous thread... please delete it Hi all i need and appreciate your help creating a script in ksh for the following case Two files exists with questionmark delemeter: File1.txt: A;B;C;F;D;K; File2.txt A,name,address1; K,name,surname,phone; C,name,phone;... (1 Reply)
Discussion started by: forumsgr
1 Replies

3. Shell Programming and Scripting

Perl parsing compared to Ksh parsing

#! /usr/local/bin/perl -w $ip = "$ARGV"; $rw = "$ARGV"; $snmpg = "/usr/local/bin/snmpbulkget -v2c -Cn1 -Cn2 -Os -c $rw"; $snmpw = "/usr/local/bin/snmpwalk -Os -c $rw"; $syst=`$snmpg $ip system sysName sysObjectID`; sysDescr.0 = STRING: Cisco Internetwork Operating System Software... (1 Reply)
Discussion started by: popeye
1 Replies

4. Shell Programming and Scripting

Perl Parsing Argument

i wanna passing an argument which read in a file or a set of files if the files are given in the command line, otherwise use STDIN if no file argument. i got something like that, but it is not really working. so can anyone help me? which one is better to use for and how? Use perl. Thank you ... (0 Replies)
Discussion started by: mingming88
0 Replies

5. UNIX for Dummies Questions & Answers

Parsing name and phone as input and then print sub and marks out

I have a file like this : name phone id sub marks abc 2345 45 mat 90 bgt 6573 54 eng 89 ... .... .. ... .. ... .... .. ... .. Now i need to take in name and phone as input and then print sub and marks out, can u give me a sample code for this. P.S. If there are two of with same... (2 Replies)
Discussion started by: SasankaBITS
2 Replies

6. Shell Programming and Scripting

Perl - pass shell-vars into perl for input loop

I need to process a file line-by-line using some value from a shell variable Something like:perl -p -e 's/$shell_srch/$shell_replace/g' input.txt I can't make the '-s' work in the '-p' or '-n' input loop (or couldn't find a syntaxis.) I have searched and found... (4 Replies)
Discussion started by: alex_5161
4 Replies

7. Shell Programming and Scripting

Help parsing job script input parameters

I have a job script that runs with input parms from the command line. job.sh -p parm1_parm2_parm3_parm4_file_1.dat The parms are separated by _ The last parm is a file name and can have an _ in the name. I currently use the following commands to extract the parms parm1=`eval echo... (3 Replies)
Discussion started by: jclanc8
3 Replies

8. Homework & Coursework Questions

Shell: Parsing Input

1. The problem statement, all variables and given/known data: I'm fairly confident I can brute force this assignment, but let's not do that ;-). Basically I'm required to support input such as ps aux | grep blah >> blah.txt& echo 'slslslsl' My question is what is the best way to parse that... (4 Replies)
Discussion started by: someoney3000
4 Replies

9. Homework & Coursework Questions

Problem parsing input with awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I want add a line.For example:- 123456 1 1 0 1 1 0 1 0 0 0 1 5 8 0 12 10 25 its answer... (4 Replies)
Discussion started by: Arsh10
4 Replies

10. Shell Programming and Scripting

Parsing C Data Tipes from Input File

Im really beginner in this case, maybe someone can help me find the answer: if my input file like this: void main(int a, int b){ int x; double y; printf("file"); } and i want output like this: int a int b int x double y A awk script that can parse only data tipe, im confused. what... (2 Replies)
Discussion started by: radynaraya
2 Replies
Test::TCP(3pm)						User Contributed Perl Documentation					    Test::TCP(3pm)

NAME
Test::TCP - testing TCP program SYNOPSIS
use Test::TCP; my $server = Test::TCP->new( code => sub { my $port = shift; ... }, ); my $client = MyClient->new(host => '127.0.0.1', port => $server->port); undef $server; # kill child process on DESTROY Using memcached: use Test::TCP; my $memcached = Test::TCP->new( code => sub { my $port = shift; exec $bin, '-p' => $port; die "cannot execute $bin: $!"; }, ); my $memd = Cache::Memcached->new({servers => ['127.0.0.1:' . $memcached->port]}); ... And functional interface is available: use Test::TCP; test_tcp( client => sub { my ($port, $server_pid) = @_; # send request to the server }, server => sub { my $port = shift; # run server }, ); DESCRIPTION
Test::TCP is test utilities for TCP/IP programs. METHODS
empty_port my $port = empty_port(); Get the available port number, you can use. test_tcp Functional interface. test_tcp( client => sub { my $port = shift; # send request to the server }, server => sub { my $port = shift; # run server }, # optional port => 8080 ); wait_port wait_port(8080); Waits for a particular port is available for connect. OO-ish interface my $server = Test::TCP->new(%args); Create new instance of Test::TCP. Arguments are following: $args{auto_start}: Boolean Call "$server->start()" after create instance. Default: true $args{code}: CodeRef The callback function. Argument for callback function is: "$code->($pid)". This parameter is required. $server->start() Start the server process. Normally, you don't need to call this method. $server->stop() Stop the server process. my $pid = $server->pid(); Get the pid of child process. my $port = $server->port(); Get the port number of child process. FAQ
How to invoke two servers? You can call test_tcp() twice! test_tcp( client => sub { my $port1 = shift; test_tcp( client => sub { my $port2 = shift; # some client code here }, server => sub { my $port2 = shift; # some server2 code here }, ); }, server => sub { my $port1 = shift; # some server1 code here }, ); Or use OO-ish interface instead. my $server1 = Test::TCP->new(code => sub { my $port1 = shift; ... }); my $server2 = Test::TCP->new(code => sub { my $port2 = shift; ... }); # your client code here. ... How do you test server program written in other languages like memcached? You can use "exec()" in child process. use strict; use warnings; use utf8; use Test::More; use Test::TCP 1.08; use File::Which; my $bin = scalar which 'memcached'; plan skip_all => 'memcached binary is not found' unless defined $bin; my $memcached = Test::TCP->new( code => sub { my $port = shift; exec $bin, '-p' => $port; die "cannot execute $bin: $!"; }, ); use Cache::Memcached; my $memd = Cache::Memcached->new({servers => ['127.0.0.1:' . $memcached->port]}); $memd->set(foo => 'bar'); is $memd->get('foo'), 'bar'; done_testing; AUTHOR
Tokuhiro Matsuno <tokuhirom@gmail.com> THANKS TO
kazuhooku dragon3 charsbar Tatsuhiko Miyagawa lestrrat SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-02-01 Test::TCP(3pm)
All times are GMT -4. The time now is 08:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy