[12225] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5825 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 29 04:07:14 1999

Date: Sat, 29 May 99 01:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 29 May 1999     Volume: 8 Number: 5825

Today's topics:
        Anyone has advices to make my script work ?? <quadid@videotron.ca>
    Re: Anyone has advices to make my script work ?? (Larry Rosler)
        Application of s/// and s%%% wired2000@my-deja.com
    Re: Application of s/// and s%%% (Larry Rosler)
    Re: Can someone help me on this challenging problem? <uyv_IGNORE_r@hotmail.com>
    Re: Can someone help me on this challenging problem? me@spam.not
    Re: Can someone help me on this challenging problem? (Gerry Quinn)
    Re: Commercial Perl Debugger/Development for Unix (Randal L. Schwartz)
    Re: Converting from ASCII to ANSI (and vice versa) (Philip 'Yes, that's my address' Newton)
    Re: Hash References (Arjun Ray)
        How do I write "target=_blank" into random link script mugitty@my-deja.com
        How do I write target=_blank into a random link script mugitty@my-deja.com
    Re: how to upload file from the form? <Anthony@Baratta.com>
    Re: Multipart Forms (David Efflandt)
    Re: Passing arguments in SSI (David Efflandt)
    Re: Perl equivalent of c++ "struct" armchair@my-deja.com
    Re: Perl equivalent of c++ "struct" (Larry Rosler)
        Perl scripts won't run on Linux jmoram@my-deja.com
    Re: Please help ? (David Efflandt)
    Re: scalar refs and m/(pat)/ <uri@sysarch.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 28 May 1999 23:13:35 -0400
From: "Quad" <quadid@videotron.ca>
Subject: Anyone has advices to make my script work ??
Message-Id: <zYI33.9243$Sm4.60271@weber.videotron.net>

I'm running the server under Win95.. and finally got a Perl interpreter for
my system.. When I write some [basic] script for the server, it always
return me "Error 500 - Internal Error" and I just can't get it to display
some html page.. Can anyone help me on that ?.. Here's my cgi script..

-----------------------------
#!/usr/bin/perl
print "Content-type:text/html\n\n";

print <<EndOfHTML;
# some html code here... no error of course
EndOfHTML
;
 ------------------------------

When I run the script under DOS, it runs ok with no error... but not with a
browser.. I have a doubt on the first line.. is it the real path that we
have to write there??.. I mean.. if the interpreter is in
C:\PERL\BIN\PERL.EXE, would I write "#!/perl/bin/perl" !?.. any advice will
be greatly appreciated !.. :)

Quad
quadid@videotron.ca




------------------------------

Date: Fri, 28 May 1999 23:29:29 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Anyone has advices to make my script work ??
Message-Id: <MPG.11b92913ebe9e41989b2e@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <zYI33.9243$Sm4.60271@weber.videotron.net> on Fri, 28 May 
1999 23:13:35 -0400, Quad <quadid@videotron.ca> says...
> I'm running the server under Win95.. and finally got a Perl interpreter for
> my system.. When I write some [basic] script for the server, it always
> return me "Error 500 - Internal Error" and I just can't get it to display
> some html page.. Can anyone help me on that ?.. Here's my cgi script..
> 
> -----------------------------
> #!/usr/bin/perl
> print "Content-type:text/html\n\n";
  print "Content-type: text/html\n\n";
                      ^  You need a space there.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Sat, 29 May 1999 06:40:14 GMT
From: wired2000@my-deja.com
Subject: Application of s/// and s%%%
Message-Id: <7io24f$rfb$1@nnrp1.deja.com>

Hi everyone,

Thank you for your recent posts in regards to my last questions about
stripping the absolute portion of the URL's (ie:
http://www.whatever.com/whatever/whatever.xxx => /whatever/whatever.xxx)

A lot of people replied with regexp strings and other various formats.
One question which I've never tried before was applying a substitution
string (s/// or s%%%) on a variable and I'm not quite sure how to do it.

For example I have data stored in $in{'URLlist'} and I would like to do
a s/// or s%%% on the data in the string, but I'm not sure exactly how
to tell Perl to do the substi. on the var.

The example suggestion that was posted to this newsgroup involved
implementing a regexp such as: s%^[a-z][a-z\d.+-]*://[^/]+%%i;
But how to tell Perl to do this to $in{'URLlist'} is bugging me.

Any ideas?

PS: Thanks again to everyone who posted in regards to my previous
thread.

Thanks
Charles


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: Sat, 29 May 1999 00:46:44 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Application of s/// and s%%%
Message-Id: <MPG.11b93b3123acafdb989b30@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7io24f$rfb$1@nnrp1.deja.com> on Sat, 29 May 1999 06:40:14 
GMT, wired2000@my-deja.com <wired2000@my-deja.com> says...
 ...
> The example suggestion that was posted to this newsgroup involved
> implementing a regexp such as: s%^[a-z][a-z\d.+-]*://[^/]+%%i;
> But how to tell Perl to do this to $in{'URLlist'} is bugging me.

Look for 'Binding Operators' in perlop.

This is really rather elementary.  You might consider investing in 
'Learning Perl on Win32 Systems', or find a good online tutorial (one 
was touted here within the past day or two).

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Fri, 28 May 1999 22:42:14 -0500
From: "Ralph Emerson" <uyv_IGNORE_r@hotmail.com>
Subject: Re: Can someone help me on this challenging problem?
Message-Id: <7innpc$i13@dfw-ixnews5.ix.netcom.com>

I compiled the c code in the hope of spending 5 hours tracing thru it to
figure it out, but it won't compile (Turbo C++ 4.5)  I included stdio.h.  I
don't think I need anything else.  The site admited that w/o reading (The
Amateur Scientist, form Scientific American magazine, March, 1997) wouldn't
understand it, but I still went on.  I read thru and it said a lot about
what people had done, but none on how it was done.  I'm allready exploring
the rest of the site for any other things I can pick up so thanks for that.



plz_reply_to_group wrote in message <374EFDD9.E7802C23@microsoft.com>...
>Check out the Algorithm of the Gods, at
>http://web2.thesphere.com/SAS/SciAm/1997/SimAneal/SimAneal.html. It is
>the elaboration of an article from Scientific American magazine, March,
>1997, about an algorithm for solving traveling-salesman-type problems.
>It's a really good article, in fact the web site is one of the best on
>the net. Really.
>
>
>Gerry Quinn wrote:
>>
>> In article <7ihfpl$t3u@dfw-ixnews11.ix.netcom.com>, "Ralph Emerson"
<uyv_IGNORE_r@hotmail.com> wrote:
>> >I thought of this one on my own but because it just seems so common, I'm
>> >sure someone else out there has done something very similar.  The way
I'm
>> >thinking of working it won't work for big input files.
>> >
>> >The number 1 connects to numbers 4,5,8 and 9.
>> >The number 2 connects to numbers 4 and 8.
>> >The number 3 connects to 5 and 6.
>> >.........
>> >The number 7 connects to nothing.
>> >.......
>> >The number 9 connects to 2,5 and 8.
>> >
>> >The input file looks like this
>> >-----------
>> >9 {The number of connectors}
>> >3 4 5 8 9
>> >4 8 9
>> >1 5 6
>> >1 2 8
>> >1 3 9
>> >3
>> >0
>> >1 2 4 9
>> >5 2 8
>> >--------------
>> >I bet you can see what I'm asking already.  Find the shortest connection
>> >path between two numbers.  For example the shortest connection between 1
and
>> >2 is 1-4-2.  The shortest connection between 6 and 2 is 6-3-5-9-2.
>> >
>> >I'm thinking a good old recursive function that calles itself with all
the
>> >numbers in it's row and stops when it hits the number it wants. (I
wouldn't
>> >have it loop back to itself somehow).  There's got to be a better way to
do
>> >this so that it will work for list 5000 long with 10-12 connectors each.
I
>> >cross posted so that I could get all the ideas I can and even though I
can
>> >read the languages I posted to, please post back ideas/Visual English
and
>> >Report Language++ and not real code so that others can comment.
>> >
>>
>> Shortest path -> A* Algorithm.  Look it up.
>>
>> - Gerry Quinn
>




------------------------------

Date: Sat, 29 May 1999 05:55:47 GMT
From: me@spam.not
Subject: Re: Can someone help me on this challenging problem?
Message-Id: <37b67da2.908855695@news.earthlink.net>

On Fri, 28 May 1999 17:25:44 -0500, "Ralph Emerson"
<uyv_IGNORE_r@hotmail.com> wrote:

>There are no people in the real world that know programming that are willing
>to teach.

Dear Waldo,

You can teach yourself.  Just don't be so lazy.

Depth first is easy.  Just search the tree in such
a way that the deepest nodes are searched in
one branch before searching other branches.
Breadth first means don't search deep till you
search part of all the branches.  The only reason
to ever use breadth first is when there is some
special bonus in the shallow parts of the branches,
such as a higher probability of finding what you
are looking for.  But depth first is conceptually
simpler and easier to implement.

P.S. I liked your poem, "Concord Hymn."




------------------------------

Date: Sat, 29 May 1999 07:17:44 GMT
From: gerryq@indigo.ie (Gerry Quinn)
Subject: Re: Can someone help me on this challenging problem?
Message-Id: <etM33.4322$yr2.1893@news.indigo.ie>

In article <7in57s$5dd@sjx-ixn10.ix.netcom.com>, "Ralph Emerson" <uyv_IGNORE_r@hotmail.com> wrote:
>>  How can you learn about
>>graph theory in a newsgroup when colleges offer one or three
>>semester courses just on that topic?
>
>I'm not asking about graph theory, only an answer to my problem.  You say
>this problem is graph theory, so?  That's only a name.  I won't put a
>limitation on my ability to learn from words, are you going to put a limit
>on your ability to teach with them?
>
>> Learning the basics of
>>graph searching using depth first and breadth first search
>>could be learned on the Internet...if you were signed up for
>>a "distance learning" course.
>
>What and where?  Also, are they free?  If they are, I would be happy to
>spend any amount of time.
>
>> Seek a teacher or book.
>
>There are no people in the real world that know programming that are willing
>to teach.
>
>> I think this thread needs
>> to die now.    <gong noise>
>
>No, no no.  Darn it I'm tired of waiting.  In elementary school I was told
>to stop learning because I'd learn algebra in Middle school.  In middle
>school nobody would teach me Calculus or show me the works of Machiavelli or
>Conrad because those were "advanced subjects" for high school or college
>people.  Now people tell me to wait because "Well, that's only for real
>programmers" or "I don't know, ask Mr. X" or "You'll learn all about that in
>college".  I'm tired of waiting.  I'm tired of stoping.  I'm tired of
>letting knowledge "Die". <gong>
>

Good for you!  As I posted earlier, the correct algorithm for your problem is 
called A*.  It can generate the shortest path for any graph, or for units 
moving on the ground in a strategy game, etc.  You will find it described in 
various places if you search, and it is quite easy to understand and 
implement.  

Just to give you the idea:
> >The input file looks like this
> >-----------
> >9 {The number of connectors}
> >3 4 5 8 9
> >4 8 9
> >1 5 6
> >1 2 8
> >1 3 9
> >3
> >0
> >1 2 4 9
> >5 2 8
> >--------------
> >I bet you can see what I'm asking already.  Find the shortest connection
> >path between two numbers.  For example the shortest connection between 1 
and
> >2 is 1-4-2.  The shortest connection between 6 and 2 is 6-3-5-9-2.
> >

Shortest path from 1->2
Mark node 1 with '1'
Mark all unmarked nodes connected to '1's with '2' 
        (that's 3,4,5,8,9)
Mark all unmarked nodes connected to '2's with '3'
        (that's 2,6) 
        (finished!)
Mark all unmarked nodes connected to '3's with '4'
        (no more changes, if I had wanted to go from 1->7 I'd stop here and 
print "No connection")

Hope that gives you the idea.  In fact you probably have enough here to do it. 
 Three semesters saved ;)


- Gerry Quinn
http://bindweed.com








------------------------------

Date: 28 May 1999 21:43:40 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Commercial Perl Debugger/Development for Unix
Message-Id: <m190a8eb9f.fsf@halfdome.holdit.com>

>>>>> "Andrew" == Andrew Wilson Falgout <afalgout@ocean.otr.usm.edu> writes:

Andrew> Does anyone know of a Commercial Development Package for 
Andrew> programming/debugging perl under the unix platform?
Andrew> (Specifically AIX and Linux)

A lot of people I know do plenty of Commercial Development using
Emacs and a command line.

What exactly did you mean?

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


------------------------------

Date: Sat, 29 May 1999 06:31:04 GMT
From: nospam.newton@gmx.net (Philip 'Yes, that's my address' Newton)
Subject: Re: Converting from ASCII to ANSI (and vice versa)
Message-Id: <374f8203.304227931@news.nikoma.de>

On Fri, 28 May 1999 10:19:25 GMT, pbk@rdsas.com (Poul Kornmod) wrote:

>Dear Eric,
>
>I'm sorry that I didn't make myself clear.
>
>You have of cause right - but what I need is be able to display,
>danish, german, swedish etc. special characters eg. "xfeXFE|\iI....."
>in Windows. The file that contains these characters is made in ASCII
>format and can be view in a DOS box using EDIT.

Hmm... I think you don't mean ASCII (which doesn't have those special
characters), but rather a DOS codepage such as 437 (US) or 850
(European?). The answer, I suspect, involves tr///. Just find a code
correspondence table (or figure one out for yourself) and run the
thing through tr/\x12\x34.../\xab\xcd.../; (finding the actual
character codes is left as an exercise for the reader).

Cheers,
Philip
-- 
Philip Newton <pne@user.picon.de>


------------------------------

Date: 29 May 1999 01:26:09 -0500
From: aray@nmds.com (Arjun Ray)
Subject: Re: Hash References
Message-Id: <380f7dba.3645177648@news1.newscene.com>

In <374ED3F8.5FE0FED8@mitre.org>, John Dixon <jdixon@mitre.org> wrote:

| Perl Gods,

Merely an Unworthy in search of the Path of Sufficient Virtue, here.
 
| I am having trouble trying to dereference an array of hashes that
| references arrays.  I access each hash list as follows:
| 
| @{$Records[$i]{$Key}}[$j]

If everything works out the way they're supposed to, the result should
be a slice (an array with one element), which is probably not what you
want (an element of an array as a scalar.)  Basically, if @Array is an
array, an element in it is $Array[$index], not @Array[$index].  This
works the same way with array references: if $Arrayref is an array
reference, then @{$Arrayref} is the array, while ${$Arrayref}[$index]
is an element of that array. It's usually cleaner to use the '->'
notation to write the latter as $Arrayref->[$index].  

Similarly with a hash reference $Hashref, %{$Hashref} is the hash, and
so ${$Hashref}{$key} or $Hashref->{$key} is keyed access to a value.
 
| where "i" iterates through each hash list and "j" iterates through
| each array element referenced by the key in the hash list.

Working from the outside in, you have an array @Records, each element
of which, $Records[$i], is a hash reference. Each such hash reference
allows keyed access to an array reference, $Records[$i]->{$Key}. Each
element of such a referenced array is thus $Records[$i]->{$Key}->[$j],
while the array itself is @{$Records[$i]->{$Key}}. Your double loop
iteration looks like this:

  foreach $record ( @Records ) {  # iterating over $i
    # $record is a hash reference 
    foreach $element ( @{$record->{$Key}} ) {  # iterating over $j
      # do stuff with $j-th element of $Key-d array in $i-th hash
    }
  }
| 
| I am having trouble storing specific hash arrays in another array.
| This is what I am currently doing:
| 
| push (@new_hash_list, %{$Records[$i]})

This would expand the hash reference into a hash of key-value pairs,
flatten the hash into a list, and append the list to the array. I'll
bet that's not what you want:) 

You probably want one of these:

  push(@new_hash_list, $Records[$i])
  push(@new_hash_list, \%{$Records[$i]})

| When I try to print the new list like this:
| 
| print @{$new_hash_list[$i]{$Key}}[$j]
| 
| Nothing prints.  Can anyone help me?

It's a good idea to put 'use strict' at the top the program, and
invoke Perl with the -w switch.


:ar


------------------------------

Date: Sat, 29 May 1999 03:53:08 GMT
From: mugitty@my-deja.com
Subject: How do I write "target=_blank" into random link script
Message-Id: <7inob4$lnj$1@nnrp1.deja.com>

Am running a random link/image script and want to
open a new browser window when it is clicked on
rather than leaving the site in the same window.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: Sat, 29 May 1999 03:59:59 GMT
From: mugitty@my-deja.com
Subject: How do I write target=_blank into a random link script
Message-Id: <7inonv$lqq$1@nnrp1.deja.com>

Am running a random link/image script from my homepage and want to open
a new browser window when the link is clicked on.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: Fri, 28 May 1999 20:53:31 -0700
From: Anthony Baratta <Anthony@Baratta.com>
Subject: Re: how to upload file from the form?
Message-Id: <374F64BB.202AC8B3@Baratta.com>

Gleb Ekker wrote:
> 
> Hi everybody,
> 
> please, help is needed. I want to upload to the server a file from the
> form.
> I use <input name='data' TYPE='file'> in the form and Perl script get
> from it only path to a file and file name.
> How can script get the file from a local machine for the futher
> processing?

get cgi-lib.pl

 http://cgi-lib.stanford.edu/cgi-lib/

Read the pages on file uploads.

-- 
Anthony Baratta
President
KeyBoard Jockeys
                    South Park Speaks Version 3 is here!!!
                       http://www.baratta.com/southpark
                              Powered by Tsunami


------------------------------

Date: 29 May 1999 04:11:48 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Multipart Forms
Message-Id: <slrn7kuq4i.hs.efflandt@efflandt.xnet.com>

Since you are using Perl 5, 'perldoc CGI' may be much more helpful and
efficient than the old cgi-lib.pl.  CGI.pm can not only generate html,
forms, tables, frames, etc., but can also process them along with file
upload.  The function-oriented method of CGI.pm can also shorten your
code.  So maybe you are simply trying to use something that is obsolete.

Just make sure you have an up to date version.  One virtual server I am on
has version 2.36, so I had to use my own copy of version 2.42 to take
advantage of newer features.

On Wed, 26 May 1999 22:18:25 GMT, news@harvest-lodge.demon.co.uk
<news@harvest-lodge.demon.co.uk> wrote:
>Help - Forms Again
>I am still trying to get a file upload to work the following gets the
>file 
>saved on the server but I am unable to access the other variables sent
>
>from the form and so cannot tell where to save the file or what to
>call 
>it.
>
>The html calling form is as follows:
>
><form enctype="multipart/form-data" method="POST" 
>action="/cgi-bin/www.name.co.uk/uploader.pl">
>Name:<select>
>        <option selected name="user" value="Null">Select Name
>        <option name="name" value="Name1">Name 1
>        <option name="name" value="Name2">Name 2
>        </select><br>
>Directory:&nbsp;<select>
>        <option selected name="dir" value="Null">Select Dir
>        <option name="name" value="dir1">Directory 1
>        <option name="name" value="dir2">Directory 2
>        </select><br>
>Password:&nbsp;<input type="password" name="password"><br>
>File to Upload&nbsp;:&nbsp;<input type="file" name="UploadedFile"><br>
><input type="reset" value="CLEAR FORM">
><input type="submit" name="SeeUploadedFile" value="UPLOAD FILE">
>
>
>
>The .pl script which is called is as follows, this saves the file in
>the 
>docs/up directory as test, but how do I access the other vars sent.
>
>No other scripts or suggestions I have had previously have I been able
>to 
>get to work on the demon server.
>
>#!/bin/perl5
>require 'CGI_LIB.pl';
>#
>#
>print "Content-type: text/html\n\n";
>&Parse_Multi;
>if (defined $CGI{'SeeUploadedFile'}) {
>$savefile="/docs/www.name/up/test";
>          open(TMP, "> $savefile");
>                print TMP $CGI{'UploadedFile'}->{'Contents'};
>          close(TMP);
>}
>
>And yes I have read all the docs I can find, so please no messages
>pointing me to cgi-lib doc.
>
>Thanks
>
>Steve


-- 
David Efflandt    efflandt@xnet.com
http://www.xnet.com/~efflandt/


------------------------------

Date: 29 May 1999 04:22:21 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Passing arguments in SSI
Message-Id: <slrn7kuqoe.hs.efflandt@efflandt.xnet.com>

Wrong newsgroup.  But the answer is Yes or No depending upon your server.
Netscape servers are the only ones I know of that accept parameters in
SSI.  For others, you can pass some parameters by linking the script to
different names for different options and have the script parse its own
name for options(s) ($0).  Otherwise you could use CGI.pm in a CGI to
generate the whole html on the fly instead of using SSI.

On Thu, 27 May 1999 16:28:41 -0400, Scott Kramer <deeto@yahoo.com> wrote:
>I'd like to have the following:
><!-- #exec cgi="cgi-bin/script.pl?myName=hello&yourName=goodbye"-->
>
>Is this possible.  The script goes through the input data as normal, as
>if it was a link being click on, but this way the script runs as soon as
>the page is accessed.
>
>
>Thanks.
>
>--
>
>
>Scott Kramer
>http://www.makeyoulaugh.com
>
>


-- 
David Efflandt    efflandt@xnet.com
http://www.xnet.com/~efflandt/


------------------------------

Date: Sat, 29 May 1999 04:25:56 GMT
From: armchair@my-deja.com
Subject: Re: Perl equivalent of c++ "struct"
Message-Id: <7inq8k$msi$1@nnrp1.deja.com>

In article <7ig5jb$7rd$1@nnrp1.deja.com>,
  steveeq1@earthlink.net wrote:
> Hey,
>
> I am trying to read some binary data and assign them into variables in
> Perl. I have done it many times in visual basic, and I kinda sort know
> how to do it in C++, but what is the command to do it in Perl?
>
> Like "read the first 5 bytes of this file and assign it to variable A.
> Then take the next 5 bytes, and assign it to variable B".
>
> Anyone know of a man page or a web page that has sample code or
> explains the concept?


A C program creates a "C datatypes" binary file:
----------------------------------------------------------
#include <stdio.h>
#include <assert.h>

void main(void)
{

  FILE *fpFile = fopen("output.file","w");
  assert(fpFile);
  double d = 4.67;
  size_t written = fwrite(&d,sizeof(double),1,fpFile);
  assert(written == 1);
  long l = 555;
  written = fwrite(&l,sizeof(long),1,fpFile);
  assert(written == 1);
  short s = 222;
  written = fwrite(&s,sizeof(short),1,fpFile);
  assert(written == 1);
  int i = 33;
  written = fwrite(&i,sizeof(int),1,fpFile);
  assert(written == 1);
  float f = 12.11;
  written = fwrite(&f,sizeof(float),1,fpFile);
  assert(written == 1);
  char *cp = "grape";
  written = fwrite(cp,sizeof(char),5,fpFile);
  assert(written == 5);
  fclose(fpFile);

}

---------------------------------------------------------------------
and a Perl program reads it:

---------------------------------------------------------------------
#!/usr/local/bin/perl -w
use diagnostics;
use strict;

my $file = "output.file";
open(FILE, "<$file") or die "could not open file: $!";
binmode(FILE);
my $data = "";
# size of the file of C datatypes on 32 bit machine
#    double + long + short + int + float + five chars
my $file_size = 8 + 4 + 2 + 4 + 4 + 5;
my $bytes = read(FILE,$data,$file_size);
if ( $bytes == $file_size )
{
  my ($double,$long,$short,$int,$float,$char) =
              unpack("dlsifa5",$data);
  print "double $double long $long short $short int $int\n";
  print            "float $float char $char\n";
}
else
{
  print "problem with file read\n";
}


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: Fri, 28 May 1999 23:18:30 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Perl equivalent of c++ "struct"
Message-Id: <MPG.11b92681f2629274989b2d@nntp.hpl.hp.com>

In article <7inq8k$msi$1@nnrp1.deja.com> on Sat, 29 May 1999 04:25:56 
GMT, armchair@my-deja.com <armchair@my-deja.com> says...
> In article <7ig5jb$7rd$1@nnrp1.deja.com>,
>   steveeq1@earthlink.net wrote:
> > I am trying to read some binary data and assign them into variables in
> > Perl. I have done it many times in visual basic, and I kinda sort know
> > how to do it in C++, but what is the command to do it in Perl?
 ...
>   FILE *fpFile = fopen("output.file","w");
                                       "wb"

 ...
> my $file = "output.file";
> open(FILE, "<$file") or die "could not open file: $!";
> binmode(FILE);

You got that one right, anyhow!  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Sat, 29 May 1999 04:04:02 GMT
From: jmoram@my-deja.com
Subject: Perl scripts won't run on Linux
Message-Id: <7inovi$m3s$1@nnrp1.deja.com>

I've just set up at a Linux box as an intranet server. Perl seems to be
installed ok, but I can't seem to run scripts. The GNU C compiler is
installed and I've made sure the scripts are executable, but when I give
the command to run them, I get this message:
$ bash: command not found <scriptname>

Is there a config file I need to modify? Any suggestions would be
appreciated. Thanks in advance.

Jay Oram


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


------------------------------

Date: 29 May 1999 05:20:27 GMT
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Please help ?
Message-Id: <slrn7kuu5c.hs.efflandt@efflandt.xnet.com>

On Wed, 26 May 1999 17:43:35 GMT, tvn007@my-deja.com <tvn007@my-deja.com> wrote:
>Hi,
>
>Would someone please help me on this ?
>
>I have the input file as follow: (just small sample )
>
>
>DATA X Y Z
>     A B C;
>
>N100 xyz 10X
>	 011;
>N10  xyz X01
>	 000;
>N12  xyz 000
>	 001;
>
>I would like the ouput as follow:
>
>DATA X Y Z A B C;
>
>N100 xyz 10X011;
>N10  xyz X01000;
>N12  xyz 000001;
>
>Here is my solution, but it does not work:
>
>while (<INFILE>) {
>
>print OUTFILE ($_\n");
>}
>
>Thanks in advance for your help !

Apparently you need to read about pattern matching.  All you did was add
extra blank lines and did not even begin to combine the data.

while ($x = <INFILE>) {
    next if $x =~ /^\s*$/;	# skip lines with no data
    chomp $x;			# prepare to append next line
    $_ = <INFILE>;		# get next line
     if (/\S\s\S/) {
        s/^\s*(\S)/ $1/;	# drop all but 1 leading space
    } else {
        s/^\s*(\S)/$1/;		# drop leading spaces
    }
    $x .= $_;			# stick 2 lines together
    print OUTFILE $x;
}

-- 
David Efflandt    efflandt@xnet.com
http://www.xnet.com/~efflandt/


------------------------------

Date: 29 May 1999 00:38:48 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: scalar refs and m/(pat)/
Message-Id: <x7g14gh4mf.fsf@home.sysarch.com>

>>>>> "RD" == Rick Delaney <rick.delaney@home.com> writes:

  RD> [posted & mailed]
  RD> Eli the Bearded wrote:
  >> 
  >> Is there some way to get m/(pat)/ type things to return scalar
  >> refs instead of just read-only copies of what was matched?

  RD> If you're just doing simple matches you could do something like:

  RD>     $one = \substr($_, index($_, $1), length($1)) if /(pat)/;

as i mentioned before check out the @+ and @- vars in some newer version
of perl (i think 5.005_5x and probably 5.006 when it is released). i
beleive they contain the starting and ending offsets which can be used
to contruct refs with substr as is done above. again whether that is
read only or the refs point into in accessible memeory is a question not
answered.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


------------------------------

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5825
**************************************

home help back first fref pref prev next nref lref last post