The first has some examples for doing exactly what you want. Ultimately, you can create command-line perl scripts...
In reading binary data, the other problem you'll encounter is trying to figure out how to get it into Perl. This is not hard, but it's not obvious. As long as your datafile will easily fit in memory, this is suitable. Otherwise, you'll want to read several bytes at a time with sysread(). (Again, see man perlfunc).
That reads in your binary file and prints out its size. $dat contains the entire image so now you can do manipulations on it with pack/unpack.
Last edited by otheus; 10-08-2008 at 01:12 PM..
Reason: Fixed post per drl
I'm having trouble with reading information back into a program from a binary file. when i try to display the contents of the file i get a Memory fault(coredump). would anyone be able to assist?
this is my fread line fread(&file_data,sizeof(struct book_type),1,fileSave); ive also tried it without... (3 Replies)
Hi I was hoping that maybe someone could help me with a small piece of C code. I have a number of files, which are all of similar layout ie. three lines of text and 5-6 columns of numerical data. I need to add each of the elements of the second column in one file to their counterparts in the second... (17 Replies)
Hi,
How can I remove all non numerical data from line, so I don't want to delete the line but to have only the numbers.
e.g.:
#########
123
aaa124
125bbb
126
127
#########
So I want all the leading and trailing non numerical stuff(letters/white space/tabs anything else except... (10 Replies)
I need to distinguish between numerical characters in a script:
echo "Enter a number."
read num
if (( $num = * )) ; then
exit 0
fi
this RegX does not work.
Any suggestions? (5 Replies)
So, I will be working with someone and basically we are trying to build a form that is submitted most likely via the web and the data is just a string of numbers.
like:
19383882872201110929282821818182827349190102837364718191001932873711
Now, each number is part of a numerical value of... (4 Replies)
this is my code and no matter what record number the user enters i cant get any of the records fields to read into the structure acct. What am i doing wrong?
#include <stdio.h>
typedef struct
{
char name;
int number;
float balance;
} acct_info_t;
int main (int... (0 Replies)
Hi experts,
I have a list of files containing forces as the only number as follows.
Force1.txt Force2.txt Force3.txt Force4.txt Force5.txt . . . . . . . . . Force100.txt I want to put all the data(only a number ) in these forces files in the file with the same order like 1,2,3 ..100 .... (2 Replies)
Hello,
I have two files, f1 and f2. f1 has 5 columns like so:
a b c d 154
e f g h 365
.....
f2 has two columns, the first column contains the name of the above file and second column contains a constant which is to be used for division.
e.g.
file1 56
I want to divide the 5th... (2 Replies)
Dear Gurus
I am stuck with the peice of work and do not know from where to start.
I get a machine generated file which is binary file contain binary data, i want to read binary data as it is without converting into any other format.
i want to read byte by byte.
Please let me know what... (24 Replies)
Discussion started by: guddu_12
24 Replies
LEARN ABOUT MOJAVE
net::netent5.18
Net::netent(3pm) Perl Programmers Reference Guide Net::netent(3pm)NAME
Net::netent - by-name interface to Perl's built-in getnet*() functions
SYNOPSIS
use Net::netent qw(:FIELDS);
getnetbyname("loopback") or die "bad net";
printf "%s is %08X
", $n_name, $n_net;
use Net::netent;
$n = getnetbyname("loopback") or die "bad net";
{ # there's gotta be a better way, eh?
@bytes = unpack("C4", pack("N", $n->net));
shift @bytes while @bytes && $bytes[0] == 0;
}
printf "%s is %08X [%d.%d.%d.%d]
", $n->name, $n->net, @bytes;
DESCRIPTION
This module's default exports override the core getnetbyname() and getnetbyaddr() functions, replacing them with versions that return
"Net::netent" objects. This object has methods that return the similarly named structure field name from the C's netent structure from
netdb.h; namely name, aliases, addrtype, and net. The aliases method returns an array reference, the rest scalars.
You may also import all the structure fields directly into your namespace as regular variables using the :FIELDS import tag. (Note that
this still overrides your core functions.) Access these fields as variables named with a preceding "n_". Thus, "$net_obj->name()"
corresponds to $n_name if you import the fields. Array references are available as regular array variables, so for example "@{
$net_obj->aliases() }" would be simply @n_aliases.
The getnet() function is a simple front-end that forwards a numeric argument to getnetbyaddr(), and the rest to getnetbyname().
To access this functionality without the core overrides, pass the "use" an empty import list, and then access function functions with their
full qualified names. On the other hand, the built-ins are still available via the "CORE::" pseudo-package.
EXAMPLES
The getnet() functions do this in the Perl core:
sv_setiv(sv, (I32)nent->n_net);
The gethost() functions do this in the Perl core:
sv_setpvn(sv, hent->h_addr, len);
That means that the address comes back in binary for the host functions, and as a regular perl integer for the net ones. This seems a bug,
but here's how to deal with it:
use strict;
use Socket;
use Net::netent;
@ARGV = ('loopback') unless @ARGV;
my($n, $net);
for $net ( @ARGV ) {
unless ($n = getnetbyname($net)) {
warn "$0: no such net: $net
";
next;
}
printf "
%s is %s%s
",
$net,
lc($n->name) eq lc($net) ? "" : "*really* ",
$n->name;
print " aliases are ", join(", ", @{$n->aliases}), "
"
if @{$n->aliases};
# this is stupid; first, why is this not in binary?
# second, why am i going through these convolutions
# to make it looks right
{
my @a = unpack("C4", pack("N", $n->net));
shift @a while @a && $a[0] == 0;
printf " addr is %s [%d.%d.%d.%d]
", $n->net, @a;
}
if ($n = getnetbyaddr($n->net)) {
if (lc($n->name) ne lc($net)) {
printf " That addr reverses to net %s!
", $n->name;
$net = $n->name;
redo;
}
}
}
NOTE
While this class is currently implemented using the Class::Struct module to build a struct-like class, you shouldn't rely upon this.
AUTHOR
Tom Christiansen
perl v5.18.2 2013-11-04 Net::netent(3pm)