Re: Edit a file inplace..

2004-07-19 Thread James Edward Gray II
On Jul 19, 2004, at 10:56 AM, [EMAIL PROTECTED] wrote:


Hi,
I am trying to edit an ASCII file in place…
I tried …
  perl -pi -ne "s/ERROR/TRACKED/g" status.log
Well, we definitely don't need -p and -n, since -p is -n plus some.
and received…
  Can't do inplace edit without backup…
Okay, let's try using a backup:
perl -pi.bak -e "s/ERROR/TRACKED/g" status.log
I believe Activestate Perl for Windows requires this.
Hope that helps.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Processing files in Multiple directories (Bash or Perl?)

2004-07-19 Thread Moon, John
Original Message-
From: Edward WIJAYA [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 19, 2004 11:37 AM
To: [EMAIL PROTECTED]
Subject: Processing files in Multiple directories (Bash or Perl?)

Hi,

I have a perl code, with usage:

mycode.pl file.txt > file1.out

Now I would like to execute this code
for files in multiple directory (e.g. dir1, dir2, dir3, ...dir10).

As I am new for both Bash and Perl, would like to know
if it is be easier to do this with Perl or Bash?


I have already have a bash script (didn't know how to proceed):

---
#!bin/bash

for i in *
do
 if [ -d $i ]
 then
find $i -name '*.fa*'

#perl mycode.pl $i > #? don't know how to go from here
  fi
done
-

Would any body kindly advice?

Thanks so much for your time.
Hope to hear from you again

Regards
Edward WIJAYA
SINGAPORE


I find this easier to do but then I know perl better than bash...

DEV,SUN2>./foo file1=a,b,c/d/e file2=x/f/g file3=/,home/cgi-bin
Find file2 in Dirs = (x/f/g)
Find file1 in Dirs = (a,b,c/d/e)
Find file3 in Dirs = (/,home/cgi-bin)
DEV,SUN2>more foo
#! /usr/local/bin/perl
use strict;
my %params;
foreach (@ARGV) {
my ($file, $dirs)=split /=/;
@{$params{$file}} = split /,/, $dirs;
}
foreach (keys %params) {
print "Find $_ in Dirs = (", join (',', @{$params{$_}}), ')', "\n";
# do any "stuff" you want then call the already existing perl script
  # like see if the file exist in the dir before calling other
script 
  # or better yet - sub ... I develop lots of things in little
blocks
  # get them working then combine... 
}
DEV,SUN2>

I also like the way read "reads" ...

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




perl.beginners Weekly list FAQ posting

2004-07-19 Thread casey
NAME
beginners-faq - FAQ for the beginners mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?
Send mail to <[EMAIL PROTECTED]>

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

<[EMAIL PROTECTED]>.

  1.2 -  How do I unsubscribe?
Now, why would you want to do that? Send mail to
<[EMAIL PROTECTED]>, and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

<[EMAIL PROTECTED]>

  1.3 - There is too much traffic on this list. Is there a digest?
Yes. To subscribe to the digest version of this list send an email to:

<[EMAIL PROTECTED]>

To unsubscribe from the digest, send an email to:

<[EMAIL PROTECTED]>

This is a high traffic list (100+ messages per day), so please subscribe
in the way which is best for you.

  1.4 - Is there an archive on the web?
Yes, there is. It is located at:

http://archive.develooper.com/beginners%40perl.org/

  1.5 - How can I get this FAQ?
This document will be emailed to the list once a week, and will be
available online in the archives, and at http://learn.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?
Send an email to <[EMAIL PROTECTED]> with your suggestion.

  1.7 - Is there a supporting website for this list?
Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who do I complain to?
You can send complaints to <[EMAIL PROTECTED]>

  1.9 - Who currently maintains the FAQ?
Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?
Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl beginners.

  1.11 - When was this FAQ last updated?
Feb 04, 2004

2 -  Questions about the 'beginners' list.
  2.1 - What is the list for?
A list for beginning Perl programmers to ask questions in a friendly
atmosphere.

  2.2 - What is this list _not_ for?
* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Monkeys
* Monkeys solicitating homework on non-Perl related SPAM.

  2.3 - Are there any rules?
Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun

  2.4 - What topics are allowed on this list?
Basically, if it has to do with Perl, then it is allowed. You can ask
CGI, networking, syntax, style, etc... types of questions. If your
question has nothing at all to do with Perl, it will likely be ignored.
If it has anything to do with Perl, it will likely be answered.

  2.5 - I want to help, what should I do?
Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?
We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

Please do not quote the documentation unless you have something to add
to it. It is better to direct someone to the documentation so they
hopefully will read documentation above and beyond that which answers
their question. It also helps teach them how to use the documentation.

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?
Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

"perldoc perldoc"

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

  2.8 Is this a high traffic list?
YES! You have been warned! If you don't want to get ~100 emails per day
from this list, consider subscribing to the digest.

  2.9 Other tips before posti

Processing files in Multiple directories (Bash or Perl?)

2004-07-19 Thread Edward WIJAYA
Hi,
I have a perl code, with usage:
mycode.pl file.txt > file1.out
Now I would like to execute this code
for files in multiple directory (e.g. dir1, dir2, dir3, ...dir10).
As I am new for both Bash and Perl, would like to know
if it is be easier to do this with Perl or Bash?
I have already have a bash script (didn't know how to proceed):
---
#!bin/bash
for i in *
do
if [ -d $i ]
then
   find $i -name '*.fa*'
#perl mycode.pl $i > #? don't know how to go from here
 fi
done
-
Would any body kindly advice?
Thanks so much for your time.
Hope to hear from you again
Regards
Edward WIJAYA
SINGAPORE
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Another Perl datatype headache ( scalars $, hashes %, and arrays @ )

2004-07-19 Thread James Edward Gray II
On Jul 18, 2004, at 7:59 PM, gohaku wrote:
Hi everyone,
Howdy.
after writing perl scripts for about 3 years now, I still have trouble 
with the
basic datatypes.
I know that variables that start with '$' are scalars.
This covers Hashes ($HASH{$key}), Arrays ( $_[0] ), and
regular scalar values ( $foobar );
Looks like you are doing good to me.
The code I write as well other's code is still unreadable to me
even though I have followed examples from the
Camel book, many other Perl books from O'Reilly and online references.
I have also used perldoc on many occasions.
I'm sorry to hear that.  Sounds like you are doing most of the right 
things.  Perhaps you just need to give it some more time.

There are still some things that haven't sunk in, such as:
If I want to add Hash keys to another Hash, I do the following:
%HASH = ( 1 => 'one' ); #NO BRACES OR ELSE
%HASH2 = ( 2 => 'two' ); AGAIN, NO BRACES OR ELSE...
@HASH2{ keys %HASH } = "";
#confusing, considering it's the symbol used for arrays
If it's confusing, let's do it a different way.
for my $key (keys %HASH) {
$HASH{$key} = "";
}
Shorter isn't always better.  Use what you can understand.
To get the length of an array, it's $#array, not [EMAIL PROTECTED] or #$array.
Usually, I use scalar @array;
$#array is not the length of the array.  It is the number (#) of the 
last scalar ($) held in the array or more simply, the last index that 
has been assigned.

scalar(@array) is the length and the way to go, so again I see no 
problem here.

Problems with subroutines where the array is the first argument
sub badsub()
{  
 
my (@array,$scalar) = @_;   
#Pass Array last!
#my ($scalar,@array) = @_:
...
}
Again, you show the fix for the problem you mention.  Looks like you 
understand a lot more than you give yourself credit for.

If you are sure your sub is called:
some_sub( @array, $scalar )
You could use:
sub some_sub {
my $scalar = pop @_;
my @array = @_;
# ...
}
But I much prefer reversing the order, as you did above.
I still don't know how to declare arrays using only '$' instead of '@'
I believe you are talking about references here.  They would be a good 
solution to the problem above.  Using them you can pass 5 arrays, 3 
hashes and 2 scalars to a sub in any order you like.

However, they complicate things a little.  If you're still having 
trouble grasping Perl without them, give it a little more time before 
running down that road.

anyway, Is it possible to write scripts using only '$' instead of 
other prefix symbols?
In other words, a php-style script written in perl
Whether it is or not, it's not the answer to your problems.
Start trying to make sense of the world you find yourself in.  There 
are rules.  Try to understand why things are happening, not just that 
they are happening.

$ is for scalars.  Even with $hash{some_key} and $array[0] we're 
talking about one entry of the group, a scalar.

@ is for when we are talking about an array as a whole:
my @array  # create array
scalar @array  # get length of array
@array = @_  # copy array
% is similar, for the hash as a whole.  For example, we don't want the 
keys() of one entry of a hash, that doesn't make sense.  We want the 
keys() of an entire hash, so we call it with:

keys %some_hash
With sub routines, everything passed is folded into an array @_.  We do 
that so subroutines can handle varying numbers of parameters with ease. 
 Because of that, if we pass an array and a scalar, they are going to 
end up in @_ together and we need to separate them back out on the 
inside.  We've seen different ways to do that above, and references 
provide yet another way.

Hopefully some of this makes sense and helps get you over the hump.  
Hang in there.

James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Pattern Matching records from a table query.

2004-07-19 Thread jason corbett
Thanks James. I am going to try this method also. Your input is very much appreciated.
 
JC

James Edward Gray II <[EMAIL PROTECTED]> wrote:
On Jul 16, 2004, at 3:46 PM, jason corbett wrote:

> I want to eliminate the ". " (periord) or "," (comma) from records 
> that I return from a query, but I cannot figure out how to approach 
> it. Does Perl have a way that I can match a string that from an array, 
> remove a character or characters?
>
>
> For example say I have array @records that contain the following:
>
> Myrecord1 Myrecord2 Myrecord3 Myrecord4 Myrecord5, inc. 
> Myrecord6, LP Myrecord7, LLC
>
> I want to send this query out to persons in a .csv file but the 
> join(",", @record) statement that I am using causes the and extra cell 
> to be created at Myrecord5, inc. Myrecord6, LP Myrecord7, LLC.

How about?

tr/.,//d foreach @records;

James


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





RE: Another Perl datatype headache ( scalars $, hashes %, and arr ays @ )

2004-07-19 Thread Hanson, Rob
> I still don't know how to declare arrays using only '$' instead of '@'

You can't.  But you can store a *reference* to an array in a scalar.

This will work:

# the backslash ("\") returns a reference to the
# variable, so this doesn't actually pass the array,
# it passes a reference (pointer sort of) to the array.
goodsub([EMAIL PROTECTED], $scalar);

sub goodsub()

{
  my ($array_ref,$scalar) = @_; 

  # turns the ref back to an actual array.
  my @array = @{$array_ref};

  # or use the array directly through the ref.
  # note that changes made through a ref will change
  # the original array.
  print $array_ref->[0];
}

> Is it possible to write scripts using only '$'
> instead of other prefix symbols?

No, not the way you intend.  You could use only references, but that
wouldn't make sense.

Rob

-Original Message-
From: gohaku [mailto:[EMAIL PROTECTED]
Sent: Sunday, July 18, 2004 8:59 PM
To: Perl Beginners
Subject: Another Perl datatype headache ( scalars $, hashes %, and
arrays @ )


Hi everyone,
after writing perl scripts for about 3 years now, I still have trouble 
with the
basic datatypes.
I know that variables that start with '$' are scalars.
This covers Hashes ($HASH{$key}), Arrays ( $_[0] ), and
regular scalar values ( $foobar );

The code I write as well other's code is still unreadable to me
even though I have followed examples from the
Camel book, many other Perl books from O'Reilly and online references.
I have also used perldoc on many occasions.

There are still some things that haven't sunk in, such as:

If I want to add Hash keys to another Hash, I do the following:

%HASH = ( 1 => 'one' ); #NO BRACES OR ELSE
%HASH2 = ( 2 => 'two' ); AGAIN, NO BRACES OR ELSE...
@HASH2{ keys %HASH } = "";
#confusing, considering it's the symbol used for arrays

To get the length of an array, it's $#array, not [EMAIL PROTECTED] or #$array.
Usually, I use scalar @array;

Problems with subroutines where the array is the first argument
sub badsub()

{

my (@array,$scalar) = @_;   
#Pass Array last!
#my ($scalar,@array) = @_:
...
}

I still don't know how to declare arrays using only '$' instead of '@'

anyway, Is it possible to write scripts using only '$' instead of other 
prefix symbols?
In other words, a php-style script written in perl

Thanks in advance.
-gohaku


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Perl and XML::Simple

2004-07-19 Thread Hanson, Rob
> 

This isn't well-formed XML.  The n=3 must be n="3".  All attributes in XML
must be quoted, either single-quotes or double-quotes.

Rob

-Original Message-
From: David Arnold [mailto:[EMAIL PROTECTED]
Sent: Monday, July 19, 2004 2:04 AM
To: [EMAIL PROTECTED]
Subject: Perl and XML::Simple


All

I tried to run this:

#! /usr/local/bin/perl -w
# File: Responses.pl

use strict;
use warnings;

# Import the SML::Simple module
use XML::Simple;
use Data::Dumper;

# Turn the file into a has reference, using XML::Simples' "XMLin"
# subroutine. We'll also turn on the 'forcearray' option, so that all
# elements contain arrayrefs.
my $resp_xml=XMLin('./Responses.xml',forcearray=>1);

print Dumper $resp_xml;

On this file:

[EMAIL PROTECTED] perlxml]# cat -A Responses.xml
 aaa$
[EMAIL PROTECTED] perlxml]#

And I got this error message:

[EMAIL PROTECTED] perlxml]# ./Responses.pl
Not a quote character [Ln: 1, Col: 38]

Can anyone help?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




[This is what I needed]Pattern Matching records from a table query.

2004-07-19 Thread jason corbett
Thanks. I was using the Pipe thing, but the fact is my client wants it in Excel and to 
be able to open it immediately and not "click around with the parameters" as they are 
not Excel friendly (go figure). I appreaciate your willingness to carry the question 
out to a solution/example and not a quick fix!
 
JC

"Charles K. Clarkson" <[EMAIL PROTECTED]> wrote:
jason corbett wrote:

: I want to eliminate the ". " (periord) or "," (comma) from
: records that I return from a query, but I cannot figure out
: how to approach it. Does Perl have a way that I can match a
: string that from an array, remove a character or characters?
: 
: 
: For example say I have array @records that contain the
: following:
: 
: Myrecord1 Myrecord2 Myrecord3 Myrecord4
: Myrecord5, inc. Myrecord6, LP Myrecord7, LLC
: 
: I want to send this query out to persons in a .csv file but
: the join(",", @record) statement that I am using causes the
: and extra cell to be created at Myrecord5, inc. Myrecord6, LP
: Myrecord7, LLC. 
:
: What I am thinking is to scan records $record[4, 5, 6] by
: using regex matching, and if a comma exists, delete it or
: replace it with ";" . I am looking for some commands to do
: this, or at least point me in the right direction.
:
: Any suggestions?

You mention an extra cell. If you are using this for
import to a spreadsheet, you should be able to wrap suspect
fileds with double quotes. Try this.

$_ = qq("$_") foreach @record[4, 5, 6];
my $record_list = join ',', @record;


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



problem while building DBD:Adabas

2004-07-19 Thread Christian Stalp
Hello out there,
I try to build a DBD:Adabas driver for DBI. And I got this dump:

# perl Makefile.PL

Configuring DBD::Adabas ...

>>> Remember to actually *READ* the README file!
And re-read it if you have any problems.

Multiple copies of Driver.xst found in: 
/usr/local/lib/perl5/5.8.3/PA-RISC2.0/auto/DBI 
/usr/local/lib/perl5/site_perl/5.8.3/PA-RISC2.0/auto/DBI at Makefile.PL line 
59
Using DBI 1.40 (for perl 5.008003 on PA-RISC2.0) installed in 
/usr/local/lib/perl5/5.8.3/PA-RISC2.0/auto/DBI
Using ODBC in /REFDB_HOME/referenz/adabas_d

Umm, this looks like a adabas type of driver manager.

Checking if your kit is complete...
Looks good
Multiple copies of Driver.xst found in: 
/usr/local/lib/perl5/5.8.3/PA-RISC2.0/auto/DBI 
/usr/local/lib/perl5/site_perl/5.8.3/PA-RISC2.0/auto/DBI at Makefile.PL line 
224
Using DBI 1.40 (for perl 5.008003 on PA-RISC2.0) installed in 
/usr/local/lib/perl5/5.8.3/PA-RISC2.0/auto/DBI
Writing Makefile for DBD::Adabas

The DBD::Adabas tests will use these values for the database connection:
DBI_DSN=dbi:Adabas:refdbe.g. dbi:Adabas:demo
DBI_USER=somewho
DBI_PASS=something


# make
cp Adabas.pm blib/lib/DBD/Adabas.pm
/usr/bin/perl -p -e "s/~DRIVER~/Adabas/g" 
/usr/local/lib/perl5/5.8.3/PA-RISC2.0/auto/DBI/Driver.xst > Adabas.xsi
/usr/bin/perl /usr/local/lib/perl5/5.8.3/ExtUtils/xsubpp  -typemap 
/usr/local/lib/perl5/5.8.3/ExtUtils/typemap  Adabas.xs > Adabas.xsc && mv 
Adabas.xsc Adabas.c
Warning: duplicate function definition 'data_sources' detected in Adabas.xs, 
line 114
/usr/local/bin/gcc -c  -I. 
-I/usr/local/lib/perl5/5.8.3/PA-RISC2.0/auto/DBI 
-I/REFDB_HOME/referenz/adabas_d/incl  -D_HPUX_SOURCE -fno-strict-aliasing 
-I/usr/local/include -D_LARGEFILE_SOURCE -O2-DVERSION=\"0.2003\"  
-DXS_VERSION=\"0.2003\" -fPIC "-I/usr/local/lib/perl5/5.8.3/PA-RISC2.0/CORE"  
 Adabas.c
In file included from dbdodbc.h:9,
 from Adabas.h:9,
 from Adabas.xs:1:
/REFDB_HOME/referenz/adabas_d/incl/WINDOWS.H:105:1: warning: "VOID" redefined
/REFDB_HOME/referenz/adabas_d/incl/WINDOWS.H:27:1: warning: this is the 
location of the previous definition
/usr/local/bin/gcc -c  -I. 
-I/usr/local/lib/perl5/5.8.3/PA-RISC2.0/auto/DBI 
-I/REFDB_HOME/referenz/adabas_d/incl  -D_HPUX_SOURCE -fno-strict-aliasing 
-I/usr/local/include -D_LARGEFILE_SOURCE -O2-DVERSION=\"0.2003\"  
-DXS_VERSION=\"0.2003\" -fPIC "-I/usr/local/lib/perl5/5.8.3/PA-RISC2.0/CORE"  
 dbdimp.c
In file included from dbdodbc.h:9,
 from Adabas.h:9,
 from dbdimp.c:12:
/REFDB_HOME/referenz/adabas_d/incl/WINDOWS.H:105:1: warning: "VOID" redefined
/REFDB_HOME/referenz/adabas_d/incl/WINDOWS.H:27:1: warning: this is the 
location of the previous definition
dbdimp.c: In function `adabas_db_login':
dbdimp.c:104: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c: In function `adabas_error':
dbdimp.c:273: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c:299: warning: passing arg 1 of `fprintf' from incompatible 
pointer typedbdimp.c:304: warning: passing arg 1 of `fprintf' from 
incompatible pointer typedbdimp.c:331: warning: passing arg 1 of `fprintf' 
from incompatible pointer typedbdimp.c: In function `dbd_preparse':
dbdimp.c:437: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c: In function `dbd_st_tables':
dbdimp.c:489: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c: In function `adabas_st_prepare':
dbdimp.c:560: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c: In function `adabas_describe':
dbdimp.c:678: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c:684: warning: passing arg 1 of `fprintf' from incompatible 
pointer typedbdimp.c:772: warning: passing arg 1 of `fprintf' from 
incompatible pointer typedbdimp.c:840: warning: passing arg 1 of `fprintf' 
from incompatible pointer typedbdimp.c: In function `adabas_st_execute':
dbdimp.c:871: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c: In function `adabas_st_fetch':
dbdimp.c:951: warning: passing arg 1 of `fprintf' from incompatible pointer 
typedbdimp.c:976: warning: passing arg 1 of `fprintf' from incompatible 
pointer typedbdimp.c: In function `_dbd_rebind_ph':
dbdimp.c:1136: warning: passing arg 1 of `fprintf' from incompatible pointer 
type
dbdimp.c:1174: warning: passing arg 1 of `fprintf' from incompatible pointer 
type
dbdimp.c:1202: warning: passing arg 1 of `fprintf' from incompatible pointer 
type
dbdimp.c:1246: warning: passing arg 1 of `fprintf' from incompatible pointer 
type
dbdimp.c: In function `adabas_bind_ph':
dbdimp.c:1319: warning: passing arg 1 of `fprintf' from incompatible pointer 
type
dbdimp.c: In function `adabas_st_blob_read':
dbdimp.c:1398: warning: passing arg 1 of `fprintf' from incompatible pointer 
type
dbdimp.c:1424: warning: passi

Re: Another Perl datatype headache ( scalars $, hashes %, and arrays @ )

2004-07-19 Thread Robin
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Mon, 19 Jul 2004 12:59, gohaku wrote:
> To get the length of an array, it's $#array, not [EMAIL PROTECTED] or #$array.
> Usually, I use scalar @array;
They do different things, afaik. $#array gives you the index of the last entry 
in the array, scalar @array gives you the size. So in general, 
[EMAIL PROTECTED]

> Problems with subroutines where the array is the first argument
> sub badsub()
> {
>   my (@array,$scalar) = @_;
>   #Pass Array last!
>   #my ($scalar,@array) = @_:
>   ...
> }
I got stuck for a while on this one. If you do this:
 my @a = (7,8,9);
 my $z = "hello";
 badsub(@a, $z);
it is turned into:
 badsub((7,8,9),"hello");
which, as Perl doesn't nest lists, and arguments are just lists, is:
 badsub(7,8,9,"hello");
you see why it gets messy now when you try to access it?

There are a few ways around it:
 badsub([EMAIL PROTECTED], $z);  # ugly, but sometimes useful if you have more than 
one list
 you want to keep apart
 badsub(@a, $z);   # where badsub has a prototype: ([EMAIL PROTECTED])
 badsub($z, @a);   # better still
I wrote a little bit about working with references here:
http://www.kallisti.net.nz/PerlTips/ReferencesPassedToSubroutines
when I got stuck. However, I've since learnt more that I need to add to that 
page. [Just done so]

> I still don't know how to declare arrays using only '$' instead of '@'
You can't, so far as I know. It doesn't make sense. @ signifies you want an 
array. $ signifies you want a scalar. Look at it this way: if you want a 
single value from something, prefix it with $. If you want a list, prefix it 
with @. If you provide a list when something is expecting a single item, it 
does 'scalar @list' which gives the size (someone correct me if I'm wrong 
here, please :)

> anyway, Is it possible to write scripts using only '$' instead of other
> prefix symbols?
> In other words, a php-style script written in perl
PHP works with them quite differently. In that, a variable starts with $ and 
may contain an array. It also doesn't have hashes like Perl (or rather, it 
doesn't have arrays like Perl, they are kind of like a mix of the two, 
similar to as if you didn't use arrays, but used hashs with '0', '1', '2' as 
the key). Note, my PHP knowledge isn't all that good, so I may not be totally 
accurate.

- -- 
Robin <[EMAIL PROTECTED]> JabberID: <[EMAIL PROTECTED]>

Hostes alienigeni me abduxerunt. Qui annus est?

PGP Key 0x776DB663 = DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFA+39EzTjgendttmMRAnOGAKCCEVl9ZkoP+sKSJP8VURdBJuMW+QCgln+L
tocP/YSbD3zRPtQEPnn+ARw=
=fxZM
-END PGP SIGNATURE-

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]