[32009] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3273 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 1 14:09:49 2011

Date: Tue, 1 Feb 2011 11:09:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 1 Feb 2011     Volume: 11 Number: 3273

Today's topics:
        access anonymous variable <nospam.gravitalsun@hotmail.com.nospam>
    Re: access anonymous variable <tzz@lifelogs.com>
    Re: access anonymous variable <peter@makholm.net>
        dynamically naming arrays <cartercc@gmail.com>
    Re: dynamically naming arrays <cartercc@gmail.com>
    Re: dynamically naming arrays <uri@StemSystems.com>
    Re: dynamically naming arrays <cartercc@gmail.com>
        hai <malargeetha20119159686702@gmail.com>
        hai <malargeetha20119159686702@gmail.com>
    Re: How to draw thin lines with Image::Magick? <josef.moellers@ts.fujitsu.com>
    Re: How to draw thin lines with Image::Magick? <sherm.pendley@gmail.com>
    Re: How to draw thin lines with Image::Magick? <josef.moellers@ts.fujitsu.com>
    Re: How to draw thin lines with Image::Magick? <glex_no-spam@qwest-spam-no.invalid>
        pulling data from a file/piping variables to if stateme <adimax@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 1 Feb 2011 14:20:58 +0200
From: "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam>
Subject: access anonymous variable
Message-Id: <ii8tqn$2igj$1@ulysses.noc.ntua.gr>

At the following example I want to alter the value of $counter variable , 
but without using the the $iter code reference.
I 've tried many tricks using __ANON__ but without luck . Can you help ?


my $iter = Create_counter(  37);

for (1..3)
{
print "$_) ". $iter->() ."\n"
}

sub Create_counter
{
my $counter = $_[0];

return sub
 {
 $counter++
 }
}





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

Date: Tue, 01 Feb 2011 09:25:51 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: access anonymous variable
Message-Id: <87k4hjsrnk.fsf@lifelogs.com>

On Tue, 1 Feb 2011 14:20:58 +0200 "George Mpouras" <nospam.gravitalsun@hotmail.com.nospam> wrote: 

GM> At the following example I want to alter the value of $counter variable , 
GM> but without using the the $iter code reference.
GM> I 've tried many tricks using __ANON__ but without luck . Can you help ?

GM> my $iter = Create_counter(  37);

GM> for (1..3)
GM> {
GM> print "$_) ". $iter->() ."\n"
GM> }

GM> sub Create_counter
GM> {
GM> my $counter = $_[0];

GM> return sub
GM>  {
GM>  $counter++
GM>  }
GM> }

Here's one way:

#!/usr/bin/perl

use warnings;
use strict;
use Modern::Perl;

{
 my $counter = 0;

 sub get_counter
 {
  $counter = shift @_ if scalar @_;
  return \$counter;
 }
}

${get_counter(37)}++; # increments the hidden $counter, starting at 37
say ${get_counter()};
${get_counter()}++; # increments the hidden $counter
say ${get_counter()};

This passes around a reference to a scoped variable; there's no other
way to access $counter outside its scope and the value of $counter will
persist between get_counter() calls.

I'll warn you that this is probably the wrong way to go unless you
really need this and know why.  Can you explain your requirements a
little bit?

Ted


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

Date: Tue, 01 Feb 2011 17:47:43 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: access anonymous variable
Message-Id: <87zkqfsnv4.fsf@vps1.hacking.dk>

"George Mpouras" <nospam.gravitalsun@hotmail.com.nospam> writes:

> At the following example I want to alter the value of $counter variable , 
> but without using the the $iter code reference.

If you really need this, it can be done with the PadWalker module. But
I would recommend against it unless you know what you are doing and
are sure that you need to do it.

//Makholm


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

Date: Tue, 1 Feb 2011 09:39:22 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: dynamically naming arrays
Message-Id: <725bce0a-aa3f-4804-a83f-0c32289ba681@a8g2000pri.googlegroups.com>

I'm processing a SQL file, and want to stuff the data into arrays that
will substitute for the database tables. I want each array element
element to be a reference to a hash. The index of the array will be my
'key', and the hash will represent the columns with the associated
values. In the real database, the key is a serial value which is
exactly the behavior of the array.

Since the SQL file will vary, I don't want to hard code the table
names, but dynamically create the arrays from the file. I've copied a
sample of the file below (from 'Beginning Databases with PostgreSQL'
by Matthew and Stoned), and the subroutine I'm using to process the
file. I create the $table, $keys, and $values for each row. I can use
a hash slice to create the hashes, but how do I create the appropriate
array (named after the table name)?

__CODE__
sub process_infile
{
    open INFILE, '<', 'pop-all-tables.sql' or die "Cannot process
INFILE, $!";
    while (<INFILE>)
    {
        next unless /^insert/ ;
        chomp;
            $_ =~ /^insert\s+into\s+   # match and skip 'insert into '
            ([^(]+)\(                  # match and save any word
character before the first open parens as $1
            ([^)]+)\)                  # match and save any word
character between the first set of parens as $2
            \ values\(                 # match and skip ' values'
            ([^)]+)\)                  # match and save any word
character between the second set of parens as $3
            /x;
            my $table = $1;
            my $keys = $2;
            my $values = $3;
            my @keys = parse_line(',', 0, $keys);
            my @values = parse_line(',', 0, $values);
            #print " TABLE $table: KEYS: [@keys] => VALUES: [@values]
\n";
            my %hash;
            @hash{@keys} = @values;
            #foreach my $key (keys %hash) { print "$key => $hash{$key}
\n"; }
            my $test = eval($table);
            print "test is $test\n";
            #push @{eval($table)}, \%hash;
    }
    close INFILE;
}

__SQL__
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Miss','Jenny','Stones','27 Rowan
Avenue','Hightown','NT2 1AQ','023 9876');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Andrew','Stones','52 The Willows','Lowtown','LT5
7RA','876 3527');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Miss','Alex','Matthew','4 The Street','Nicetown','NT2
2TX','010 4567');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Adrian','Matthew','The Barn','Yuleville','YV67
2WR','487 3871');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Simon','Cozens','7 Shady Lane','Oakenham','OA3
6QW','514 5926');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Neil','Matthew','5 Pasture Lane','Nicetown','NT3
7RT','267 1232');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Richard','Stones','34 Holly Way','Bingham','BG4
2WE','342 5982');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mrs','Ann','Stones','34 Holly Way','Bingham','BG4
2WE','342 5982');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mrs','Christine','Hickman','36 Queen
Street','Histon','HT3 5EM','342 5432');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Mike','Howard','86 Dysart Street','Tibsville','TB3
7FG','505 5482');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Dave','Jones','54 Vale Rise','Bingham','BG3
8GD','342 8264');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Richard','Neill','42 Thatched
Way','Winnersby','WB3 6GQ','505 6482');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mrs','Laura','Hardy','73 Margarita Way','Oxbridge','OX2
3HX','821 2335');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','Bill','O\'Neill','2 Beamer Street','Welltown','WT3
8GM','435 1234');
insert into customer(title, fname, lname, addressline, town, zipcode,
phone) values('Mr','David','Hudson','4 The Square','Milltown','MT2
6RT','961 4526');


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

Date: Tue, 1 Feb 2011 10:25:00 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: dynamically naming arrays
Message-Id: <e9de3e91-ce27-44f8-82a6-9c54563f6b5e@y36g2000pra.googlegroups.com>

On Feb 1, 12:39=A0pm, ccc31807 <carte...@gmail.com> wrote:

Never mind. I bit the bullet, did an Indiana Jones, and used a global
hash instead.

Each hash element is a reference to an array, and each array is a
reference to a hash. The syntax is the typical Perl 'write once, read
never' mess, but it works.

CC.


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

Date: Tue, 01 Feb 2011 13:27:16 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: dynamically naming arrays
Message-Id: <87k4hj3917.fsf@quad.sysarch.com>

>>>>> "c" == ccc31807  <cartercc@gmail.com> writes:

  c> On Feb 1, 12:39 pm, ccc31807 <carte...@gmail.com> wrote:
  c> Never mind. I bit the bullet, did an Indiana Jones, and used a global
  c> hash instead.

global? no need for a global. just pass the reference around.

also XML::Simple will parse the xml to a perl data tree in one call.

  c> Each hash element is a reference to an array, and each array is a
  c> reference to a hash. The syntax is the typical Perl 'write once,
  c> read never' mess, but it works.

arrays can't be references to hashes. they can CONTAIN hash refs. that
is called a perl data tree and is very common.

and that is YOUR typical mess. good perl code doesn't make a mess of
data.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Tue, 1 Feb 2011 10:34:21 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: dynamically naming arrays
Message-Id: <ee5a6596-89f9-44cd-b4e6-fc2481ea170d@k14g2000pre.googlegroups.com>

On Feb 1, 1:27=A0pm, "Uri Guttman" <u...@StemSystems.com> wrote:
> and that is YOUR typical mess. good perl code doesn't make a mess of
> data.

Okay, Uir, I'm teachable. Here is my code and the output. Give me some
pointers on how to clean up the mess.

Thanks, CC.

__CODE__
sub process_infile
{
    open INFILE, '<', 'pop-all-tables.sql' or die "Cannot process
INFILE, $!";
    while (<INFILE>)
    {
        next unless /^insert/ ;
        chomp;
            $_ =3D~ /^insert\s+into\s+   # match and skip 'insert into '
            ([^(]+)\(                  # match and save any word
character before the first open parens as $1
            ([^)]+)\)                  # match and save any word
character between the first set of parens as $2
            \ values\(                 # match and skip ' values'
            ([^)]+)\)                  # match and save any word
character between the second set of parens as $3
            /x;
            my $table =3D $1;
            my $keys =3D $2;
            my $values =3D $3;
            $table =3D~ s/ //g;
            $keys =3D~ s/ //g;
            my @keys =3D parse_line(',', 0, $keys);
            my @values =3D parse_line(',', 0, $values);
            #print " TABLE $table: KEYS: [@keys] =3D> VALUES: [@values]
\n";
            my %hash;
            @hash{@keys} =3D @values;
            #foreach my $key (keys %hash) { print "$key =3D> $hash{$key}
\n"; }
            push @{$database{$table}}, \%hash;
    }
    close INFILE;
}

sub test_hash
{
    foreach my $k1 (keys %database)
    {
        print "$k1 =3D> $database{$k1}\n";
        foreach my $ele (@{$database{$k1}})
        {
            print "   $ele =3D>\n";
            foreach my $k2 (keys %{$ele})
            {
                print "    $k2 =3D> $ele->{$k2}\n";
            }
        }
    }
}

__OUTPUT__
customer =3D> ARRAY(0x184796c)
   HASH(0x184768c) =3D>
    addressline =3D> 27 Rowan Avenue
    lname =3D> Stones
    fname =3D> Jenny
    town =3D> Hightown
    title =3D> Miss
    phone =3D> 023 9876
    zipcode =3D> NT2 1AQ
   HASH(0x184797c) =3D>
    addressline =3D> 52 The Willows
    lname =3D> Stones
    fname =3D> Andrew
    town =3D> Lowtown
    title =3D> Mr
    phone =3D> 876 3527
    zipcode =3D> LT5 7RA
   HASH(0x1847a3c) =3D>
    addressline =3D> 4 The Street
    lname =3D> Matthew
    fname =3D> Alex
    town =3D> Nicetown
    title =3D> Miss
    phone =3D> 010 4567
    zipcode =3D> NT2 2TX
   HASH(0x1847aec) =3D>
    addressline =3D> The Barn
    lname =3D> Matthew
    fname =3D> Adrian
    town =3D> Yuleville
    title =3D> Mr
    phone =3D> 487 3871
    zipcode =3D> YV67 2WR
   HASH(0x1847b7c) =3D>
    addressline =3D> 7 Shady Lane
    lname =3D> Cozens
    fname =3D> Simon
    town =3D> Oakenham
    title =3D> Mr
    phone =3D> 514 5926
    zipcode =3D> OA3 6QW
   HASH(0x1847c0c) =3D>
    addressline =3D> 5 Pasture Lane
    lname =3D> Matthew
    fname =3D> Neil
    town =3D> Nicetown
    title =3D> Mr
    phone =3D> 267 1232
    zipcode =3D> NT3 7RT
   HASH(0x1847c9c) =3D>
    addressline =3D> 34 Holly Way
    lname =3D> Stones
    fname =3D> Richard
    town =3D> Bingham
    title =3D> Mr
    phone =3D> 342 5982
    zipcode =3D> BG4 2WE
   HASH(0x1847d2c) =3D>
    addressline =3D> 34 Holly Way
    lname =3D> Stones
    fname =3D> Ann
    town =3D> Bingham
    title =3D> Mrs
    phone =3D> 342 5982
    zipcode =3D> BG4 2WE
   HASH(0x1847dbc) =3D>
    addressline =3D> 36 Queen Street
    lname =3D> Hickman
    fname =3D> Christine
    town =3D> Histon
    title =3D> Mrs
    phone =3D> 342 5432
    zipcode =3D> HT3 5EM
   HASH(0x1847e4c) =3D>
    addressline =3D> 86 Dysart Street
    lname =3D> Howard
    fname =3D> Mike
    town =3D> Tibsville
    title =3D> Mr
    phone =3D> 505 5482
    zipcode =3D> TB3 7FG
   HASH(0x1847edc) =3D>
    addressline =3D> 54 Vale Rise
    lname =3D> Jones
    fname =3D> Dave
    town =3D> Bingham
    title =3D> Mr
    phone =3D> 342 8264
    zipcode =3D> BG3 8GD
   HASH(0x1847f6c) =3D>
    addressline =3D> 42 Thatched Way
    lname =3D> Neill
    fname =3D> Richard
    town =3D> Winnersby
    title =3D> Mr
    phone =3D> 505 6482
    zipcode =3D> WB3 6GQ
   HASH(0x1847ffc) =3D>
    addressline =3D> 73 Margarita Way
    lname =3D> Hardy
    fname =3D> Laura
    town =3D> Oxbridge
    title =3D> Mrs
    phone =3D> 821 2335
    zipcode =3D> OX2 3HX
   HASH(0x184808c) =3D>
    addressline =3D> 2 Beamer Street
    lname =3D> O\'Neill
    fname =3D> Bill
    town =3D> Welltown
    title =3D> Mr
    phone =3D> 435 1234
    zipcode =3D> WT3 8GM
   HASH(0x184811c) =3D>
    addressline =3D> 4 The Square
    lname =3D> Hudson
    fname =3D> David
    town =3D> Milltown
    title =3D> Mr
    phone =3D> 961 4526
    zipcode =3D> MT2 6RT
orderinfo =3D> ARRAY(0x187145c)
   HASH(0x18713ec) =3D>
    date_placed =3D> 03-13-2004
    customer_id =3D> 3
    date_shipped =3D> 03-17-2004
    shipping =3D>  2.99
   HASH(0x187146c) =3D>
    date_placed =3D> 06-23-2004
    customer_id =3D> 8
    date_shipped =3D> 06-24-2004
    shipping =3D>  0.00
   HASH(0x18714cc) =3D>
    date_placed =3D> 09-02-2004
    customer_id =3D> 15
    date_shipped =3D> 09-12-2004
    shipping =3D>  3.99
   HASH(0x187154c) =3D>
    date_placed =3D> 09-03-2004
    customer_id =3D> 13
    date_shipped =3D> 09-10-2004
    shipping =3D>  2.99
   HASH(0x18715ac) =3D>
    date_placed =3D> 07-21-2004
    customer_id =3D> 8
    date_shipped =3D> 07-24-2004
    shipping =3D>  0.00
item =3D> ARRAY(0x184817c)
   HASH(0x18481ac) =3D>
    sell_price =3D>  21.95
    description =3D> Wood Puzzle
    cost_price =3D>  15.23
   HASH(0x184821c) =3D>
    sell_price =3D>  11.49
    description =3D> Rubik Cube
    cost_price =3D>  7.45
   HASH(0x184825c) =3D>
    sell_price =3D>  2.49
    description =3D> Linux CD
    cost_price =3D>  1.99
   HASH(0x18481ec) =3D>
    sell_price =3D>  3.99
    description =3D> Tissues
    cost_price =3D>  2.11
   HASH(0x18482cc) =3D>
    sell_price =3D>  9.95
    description =3D> Picture Frame
    cost_price =3D>  7.54
   HASH(0x184831c) =3D>
    sell_price =3D>  15.75
    description =3D> Fan Small
    cost_price =3D>  9.23
   HASH(0x184836c) =3D>
    sell_price =3D>  19.95
    description =3D> Fan Large
    cost_price =3D>  13.36
   HASH(0x18483bc) =3D>
    sell_price =3D>  1.45
    description =3D> Toothbrush
    cost_price =3D>  0.75
   HASH(0x184840c) =3D>
    sell_price =3D>  2.45
    description =3D> Roman Coin
    cost_price =3D>  2.34
   HASH(0x184845c) =3D>
    sell_price =3D>  0.0
    description =3D> Carrier Bag
    cost_price =3D>  0.01
   HASH(0x18484ac) =3D>
    sell_price =3D>  25.32
    description =3D> Speakers
    cost_price =3D>  19.73
barcode =3D> ARRAY(0x184854c)
   HASH(0x18484fc) =3D>
    barcode_ean =3D> 6241527836173
    item_id =3D>  1
   HASH(0x1870f0c) =3D>
    barcode_ean =3D> 6241574635234
    item_id =3D>  2
   HASH(0x184851c) =3D>
    barcode_ean =3D> 6264537836173
    item_id =3D>  3
   HASH(0x1870f4c) =3D>
    barcode_ean =3D> 6241527746363
    item_id =3D>  3
   HASH(0x1870f8c) =3D>
    barcode_ean =3D> 7465743843764
    item_id =3D>  4
   HASH(0x1870fcc) =3D>
    barcode_ean =3D> 3453458677628
    item_id =3D>  5
   HASH(0x187100c) =3D>
    barcode_ean =3D> 6434564564544
    item_id =3D>  6
   HASH(0x187104c) =3D>
    barcode_ean =3D> 8476736836876
    item_id =3D>  7
   HASH(0x187108c) =3D>
    barcode_ean =3D> 6241234586487
    item_id =3D>  8
   HASH(0x18710cc) =3D>
    barcode_ean =3D> 9473625532534
    item_id =3D>  8
   HASH(0x187110c) =3D>
    barcode_ean =3D> 9473627464543
    item_id =3D>  8
   HASH(0x187114c) =3D>
    barcode_ean =3D> 4587263646878
    item_id =3D>  9
   HASH(0x187118c) =3D>
    barcode_ean =3D> 9879879837489
    item_id =3D>  11
   HASH(0x18711cc) =3D>
    barcode_ean =3D> 2239872376872
    item_id =3D>  11
orderline =3D> ARRAY(0x187166c)
   HASH(0x187160c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 1
    item_id =3D>  4
   HASH(0x187167c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 1
    item_id =3D>  7
   HASH(0x187163c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 1
    item_id =3D>  9
   HASH(0x187170c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 2
    item_id =3D>  1
   HASH(0x187175c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 2
    item_id =3D>  10
   HASH(0x18717ac) =3D>
    quantity =3D>  2
    orderinfo_id =3D> 2
    item_id =3D>  7
   HASH(0x18717fc) =3D>
    quantity =3D>  2
    orderinfo_id =3D> 2
    item_id =3D>  4
   HASH(0x187184c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 3
    item_id =3D>  2
   HASH(0x187189c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 3
    item_id =3D>  1
   HASH(0x18718ec) =3D>
    quantity =3D>  2
    orderinfo_id =3D> 4
    item_id =3D>  5
   HASH(0x187193c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 5
    item_id =3D>  1
   HASH(0x187198c) =3D>
    quantity =3D>  1
    orderinfo_id =3D> 5
    item_id =3D>  3
stock =3D> ARRAY(0x187125c)
   HASH(0x187120c) =3D>
    quantity =3D> 12
    item_id =3D> 1
   HASH(0x18712ac) =3D>
    quantity =3D> 2
    item_id =3D> 2
   HASH(0x187128c) =3D>
    quantity =3D> 8
    item_id =3D> 4
   HASH(0x18712ec) =3D>
    quantity =3D> 3
    item_id =3D> 5
   HASH(0x187132c) =3D>
    quantity =3D> 8
    item_id =3D> 7
   HASH(0x187136c) =3D>
    quantity =3D> 18
    item_id =3D> 8
   HASH(0x18713ac) =3D>
    quantity =3D> 1
    item_id =3D> 10


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

Date: Tue, 1 Feb 2011 05:02:52 -0800 (PST)
From: geethu <malargeetha20119159686702@gmail.com>
Subject: hai
Message-Id: <4c7a3add-dd96-4ef4-8e79-e636e5daeec4@o21g2000prn.googlegroups.com>

malargeetha20119159686702@gmail.com |


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

Date: Tue, 1 Feb 2011 05:02:51 -0800 (PST)
From: geethu <malargeetha20119159686702@gmail.com>
Subject: hai
Message-Id: <ec538316-5231-4f48-8b8a-2b6ab66144f6@n36g2000pre.googlegroups.com>

malargeetha20119159686702@gmail.com |


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

Date: Tue, 01 Feb 2011 16:17:15 +0100
From: Josef Moellers <josef.moellers@ts.fujitsu.com>
Subject: Re: How to draw thin lines with Image::Magick?
Message-Id: <ii985s$fb8$1@nntp.fujitsu-siemens.com>

Am 1.2.2011 schrub Steve M.:

> On Mon, 31 Jan 2011 15:09:22 +0100, Josef Moellers wrote:
> 
>> Hi,
>>
>> I'd like to draw lines only one pixel thin using Image::Magick. The
>> following draws lines two pixels thick:
>>
>> #! /usr/bin/perl
>>
>> use warnings;
>> use strict;
>> use Image::Magick;
>>
>> my $img = Image::Magick->new(size => '22x22');
>> $img->ReadImage('xc:white');
>> $img->Draw(primitive => 'line',
>>            linewidth => 1,   <- ??????
>>            method => 'point',
>>            points => '0,10 20,10',
>>            fill => 'black',
>>            antialias => 'false',
>>           );
>> $img->Transparent(color => 'white');
>> $img->Write('thick.png');
>>
>>
>> What options are required to draw lines one pixel wide? Besides
>> "linewidth" I also tried "strikewidth" to no avail.
>>
>> Josef
> 
> Well...
> 
> $img -> Draw (
>   stroke      => 'black',
>   primitive   => 'line',
>   strokewidth => '1',
>   points      => '1,10 20,10',
>   antialias   => 'false',
> );
> 
> should work.


Thanks but ... the line is still 2 pixels wide.

> I'm not sure where linewidth came from... strikewidth appears to be a 
> typo...

I found the linewidth in some documentation, so I just gave it a try.
The str*i*kewith was indeed a typo: strokewidth => 1 does not work either.

Thanks anyway,

Josef

NB My perl is 5.10.1, my perlmagick is "ImageMagick 6.5.7-8 2010-12-02
Q16 http://www.imagemagick.org"
-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


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

Date: Tue, 01 Feb 2011 10:49:21 -0500
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: How to draw thin lines with Image::Magick?
Message-Id: <m2r5brsqke.fsf@sherm.shermpendley.com>

Josef Moellers <josef.moellers@ts.fujitsu.com> writes:

> I'd like to draw lines only one pixel thin using Image::Magick.
> The following draws lines two pixels thick:

Fair warning: I'm not familiar with IM. This is just an idea based on
my experience with other drawing APIs, so I apologize in advance if it
doesn't apply!

Is IM's drawing based on pixel coordinates, or on image coordinates?
For the former, X/Y coordinates denote the center points of pixels, so
a one-pixel line is exactly one pixel thick.

But, in image coordinates, X/Y denote the top left of a pixel, so that
integer coordinates represent the lines between pixels. With antialias-
ing, a one-pixel wide line would be rendered by coloring two adjacent
pixels at half value. To draw a true one-pixel line in such systems,
one must add 0.5 to both X and Y coordinates.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Tue, 01 Feb 2011 17:30:22 +0100
From: Josef Moellers <josef.moellers@ts.fujitsu.com>
Subject: Re: How to draw thin lines with Image::Magick?
Message-Id: <ii9ceu$uni$1@nntp.fujitsu-siemens.com>

Am 1.2.2011 schrub Sherm Pendley:

> Josef Moellers <josef.moellers@ts.fujitsu.com> writes:
> 
>> I'd like to draw lines only one pixel thin using Image::Magick.
>> The following draws lines two pixels thick:
> 
> Fair warning: I'm not familiar with IM. This is just an idea based on
> my experience with other drawing APIs, so I apologize in advance if it
> doesn't apply!
> 
> Is IM's drawing based on pixel coordinates, or on image coordinates?
> For the former, X/Y coordinates denote the center points of pixels, so
> a one-pixel line is exactly one pixel thick.
> 
> But, in image coordinates, X/Y denote the top left of a pixel, so that
> integer coordinates represent the lines between pixels. With antialias-
> ing, a one-pixel wide line would be rendered by coloring two adjacent
> pixels at half value. To draw a true one-pixel line in such systems,
> one must add 0.5 to both X and Y coordinates.


Now you did it! ;-)
Now the lines are 3 pixels wide!

It's certainly an idea worth investigating.

Thanks,

Josef
-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html


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

Date: Tue, 01 Feb 2011 11:59:35 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: How to draw thin lines with Image::Magick?
Message-Id: <4d484a08$0$73616$815e3792@news.qwest.net>

Josef Moellers wrote:
>> Josef Moellers <josef.moellers@ts.fujitsu.com> writes:
>>
>>> I'd like to draw lines only one pixel thin using Image::Magick.
>>> The following draws lines two pixels thick:


Looking at 
http://www.smileygenerator.us/history/imagick6/draw/index.html#strokewidth

Try strokewidth => 0


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

Date: Tue, 1 Feb 2011 10:50:28 -0800 (PST)
From: Adimax <adimax@gmail.com>
Subject: pulling data from a file/piping variables to if statement...
Message-Id: <8a420ace-bf98-435e-a60a-dce688c15dd1@e21g2000yqe.googlegroups.com>

Very new to perl, but not programming in general. What I'm trying to
do is get a dynamically changing file in list format - something like:

apple
orange
pear

and get the code to pull that into an if statement. I've gotten as far
as being able to print the list:

% open (FILE, "/var/www/test");
% my @custom = <FILE>;
% chomp @custom;
% # print "@custom"; # this prints out 'apple orange pear'
% close FILE;

And my if statement works if I define it specifically:

% if ($server eq "apple" or $server eq "orange" or $server eq "pear")
{
display some text
% }
% } # endif $server

However, if I try to use something like:

% # if ($server eq @custom) {
display some text
% }
% } # endif $server

every $server is included in the 'display some text'.  I know I'm off
a bit here, but any help or references to examples would be greatly
appreciated.

Benjamin


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3273
***************************************


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