Re: Licensing code

2009-05-08 Thread Chas. Owens
On Fri, May 8, 2009 at 00:51, Steve Bertrand  wrote:
snip
> I wish all of my code be free, ie: I don't care if a commercial entity
> uses it for their benefit or not, I don't care if derivatives are used
> in commercial products or not, all I really care about is that my
> current code is protected so that it can not be "claimed" as anyone
> elses, currently... if that makes sense.
>
> Am I allowed to put in any license I choose into files containing my own
> code, so long as I honour all licences within any modules which I may
> have included?
>
> If I do add a license into my files, does that take effect immediately?
snip

I can't speak for Canada, but in the US your first desire is handled
by copyright law.  The second you put pen to paper or fingers to
keyboard your work is protected; however, you need to be able to prove
that the work is yours.  Due to the way copyright law works, no one
has the right to copy or run your code without a license.  This is why
the GPL works.

Your code is your own, and you can put any license on it that you
want.  So long as you are only including code via use, require, or the
like, the licenses of the other modules will have no effect on you.
Just make sure you have the right to distribute those modules (it is a
requirement for being hosted on CPAN, so if you got the module there
you should be fine).

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Reading/writing binary

2009-05-08 Thread Raymond Wan
Hi Chas,

On 5/7/09, Chas. Owens  wrote:
> You use pack to create a binary value and unpack to read a binary
> value.  So, to write a file containing three 32 bit integers you say

[snip]

Thanks for the sample code; that worked exactly as you said.  I wasn't
getting anywhere with google; I thought the key was to get it working
with the b/B [bit string] templates...I wasn't close at all. :-)

Thanks a lot!

Ray

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Reading/writing binary

2009-05-08 Thread Chas. Owens
On Fri, May 8, 2009 at 03:20, Raymond Wan  wrote:
> Hi Chas,
>
> On 5/7/09, Chas. Owens  wrote:
>> You use pack to create a binary value and unpack to read a binary
>> value.  So, to write a file containing three 32 bit integers you say
>
> [snip]
>
> Thanks for the sample code; that worked exactly as you said.  I wasn't
> getting anywhere with google; I thought the key was to get it working
> with the b/B [bit string] templates...I wasn't close at all. :-)
>
> Thanks a lot!
>
> Ray
>

The place to go is http://perldoc.perl.org, and in your case
http://perldoc.perl.org/functions/pack.html and
http://perldoc.perl.org/functions/unpack.html.  You can also get these
docs on your machine by saying

perldoc -f pack
perldoc -f unpack

The key with pack and unpack is to use the right template character.
In the example, I used l which will turn a Perl number in to a binary
signed 32 bit integer.  If I had wanted them to be unsigned I could
have used L.  The documentation for pack lists what the various
templates are and what they do.  The unpack function uses the same
templates, but in reverse.

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Reading/writing binary

2009-05-08 Thread Raymond Wan
Hi John,


On 5/8/09, John W. Krahn  wrote:

[snip]

> That is equivalent in C to:
>
> unsigned char decimal_number = 42;
>
> Or another way to write that in Perl is:
>
> my $decimal_number = pack 'C', 42;
>
>
> Once you have created the appropriate strings using pack() then just
> print() them.


I see; thanks for the explanation.  I never used Perl for bits before,
so pack/unpack is still  new to me.  Until now, I just envisioned that
everything happens magically behind the scenes for me.  :-)

At this moment, I got it to work by not opening a file for binary
output.  Instead, I just print ()
to STDOUT.  It seems specifying whether the output file is binary or
now doesn't matter?  I thought it would...

Thanks again!

Ray

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Reading/writing binary

2009-05-08 Thread Raymond Wan
Hi Chas.,

On 5/8/09, Chas. Owens  wrote:
> The place to go is http://perldoc.perl.org, and in your case
> http://perldoc.perl.org/functions/pack.html and
> http://perldoc.perl.org/functions/unpack.html.  You can also get these
> docs on your machine by saying
>
> perldoc -f pack
> perldoc -f unpack
>
> The key with pack and unpack is to use the right template character.
> In the example, I used l which will turn a Perl number in to a binary
> signed 32 bit integer.  If I had wanted them to be unsigned I could
> have used L.  The documentation for pack lists what the various
> templates are and what they do.  The unpack function uses the same
> templates, but in reverse.


I see; thanks!  I was reading perldoc on the Web; didn't realize a -f
was required for the command line.  It's quite clear it's needed if I
had read the man pages of perldoc..  Thanks!

Ray

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




RE: Licensing code

2009-05-08 Thread Bob McConnell
From: Steve Bertrand
> Chas. Owens wrote:
>> On Thu, May 7, 2009 at 22:04, Steve Bertrand 
wrote:
>> snip
>>> I like the BSD license, and I am a BSD person, but I'm asking for
>>> feedback from the creme-de-la-creme with regards to making code
public,
>>> so that I can put something in my code to ensure that someone else
>>> doesn't decide that they want to "claim" it.
>> snip
>> 
>> Given your desire to keep the code free (i.e. not allow people to
>> create closed source forks), your best option is the GPLv2[1] or
>> GPLv3[2] licenses.  Perl itself and many of its modules are dual
>> licensed under GPLv1[3] or later license and the Artistic License[4].
>> 
>> The GPL basically says that you must provide the source code in the
>> preferred form to people you give or sell the binaries to (if they
ask
>> for it).
>> 
>> The Artistic License is similar, but a bit more free (the GPL gets a
>> bit hinky when you want to combine GPL and commercial code).
> 
> [snip]
> 
> Thanks Chas, for the response.
> 
> I'm a network engineer, naturally, I hate legal stuff. Given what
you've
> said, I'll rephrase:
> 
> I wish all of my code be free, ie: I don't care if a commercial entity
> uses it for their benefit or not, I don't care if derivatives are used
> in commercial products or not, all I really care about is that my
> current code is protected so that it can not be "claimed" as anyone
> elses, currently... if that makes sense.
> 
> Am I allowed to put in any license I choose into files containing my
own
> code, so long as I honour all licences within any modules which I may
> have included?
> 
> If I do add a license into my files, does that take effect
immediately?

You are talking about two different states Steve, and they are mutually
exclusive. First off, public domain is not a license, it is a specific
condition that is exempt from licensing. It means it is totally free of
all copy rights. You simply put a statement into the file that says you
release this file into the public domain and it is done. Once you
release it, you have given it away and there is no way to get control
back. It takes effect as soon as you make the marked file publicly
accessible. You can see Bob Stout's Snippets site  for
examples.

If you do want to retain some modicum of control, then you need to
select a license. That is when you would get into the discussion between
free software and open source. But it sounds like you prefer the public
domain option.

Bob McConnell

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Reading/writing binary

2009-05-08 Thread John W. Krahn

Raymond Wan wrote:


On 5/8/09, John W. Krahn  wrote:

[snip]


That is equivalent in C to:

unsigned char decimal_number = 42;

Or another way to write that in Perl is:

my $decimal_number = pack 'C', 42;


Once you have created the appropriate strings using pack() then just
print() them.



I see; thanks for the explanation.  I never used Perl for bits before,
so pack/unpack is still  new to me.  Until now, I just envisioned that
everything happens magically behind the scenes for me.  :-)

At this moment, I got it to work by not opening a file for binary
output.  Instead, I just print ()
to STDOUT.  It seems specifying whether the output file is binary or
now doesn't matter?  I thought it would...


That depends on the operating system you are using.  I use Linux so 
there is no difference between "binary" and "text", except for those 
specific applications that can't handle "binary" data.  If you are on a 
system like DOS/Windows then reading or writing "binary" data as "text" 
will cause problems because line ending translation occurs with "text" 
files but not with "binary" files.




John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: newbie needs help with first perl prog

2009-05-08 Thread John W. Krahn

Prince Mavi wrote:

Hi folks


Hello,


I am new to perl. this is my first real program in perl.
The program is not doing what i intend it to do.
The problem in nut shell is that:
I expect to see the menu first and then input my choice.
but
the program asks for my choice first and then displays the menu

Please have a look and see what am i doing wrong.

Thanks a ton for your time guys.


code
--
#!/usr/bin/perl
use strict;
use warnings;

sub dispBlanks {
print "\n\n";
}

sub clrScr {
system("clear");
}

sub dispMenu {
clrScr;
print "\n\n=== Student Manage Pro ===\n";
print "1. Display all students\n";
print "2. Display a particular student\n";
print "3. Add a new student\n";
print "4. Delete a student\n";
print "0. Exit\n";
print "Please choose one of the options\n";
}

while (1) {
dispMenu
my $choice = ;


Your problem is here.  You are calling the subroutine 'dispMenu' with 
the argument 'my $choice = '.  In order to pass the value of the 
expression 'my $choice = ' to the subroutine 'dispMenu' the 
expression must be evaluated first so you must provide an option before 
the menu is displayed.




chomp($choice); # to remove newline
print "you chose $choice";


Once that is fixed then this line will only diplay for a tiny fraction 
of a second as you loop around and clear the screen right away.




dispBlanks;
} 
--


I would do it using strings instead of subroutines:

# #!/usr/bin/perl
use strict;
use warnings;

my $dispBlanks = "\n\n";
my $clrScr = `clear`;
my $dispMenu   = <;
chomp $choice;  # to remove newline
last if $choice == 0;
print "you chose $choice", $dispBlanks;
}

__END__



John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Licensing code

2009-05-08 Thread Randal L. Schwartz
> ""Chas" == "Chas Owens"  writes:

"Chas> Neither license prevents people from selling the software in question,
"Chas> but both require that source be available (or made available), so
"Chas> anyone charging an arm and a leg for it will rapidly find free
"Chas> versions being made available (see CentOS and RedHat for an example).

No, the Artistic license is much more like a MIT/BSD-style license, which
basically permits the recipient of your work nearly every right you also
have. The recipient is free to incorporate your work into their commercial
product, and never share the source code of the derived work.  Some of us
consider this a Good Thing.

Basically, GPL retains many rights to the author, making it an assymetric
relationship, effectively distrusting any second or third or fourth party by
making the originator a special case.  The Artistic license gives away nearly
every right to the recipients, equally trusting that they'll "do the right
thing" more often than not.  Think of the GPL as "socialism by force" and the
Artistic as "socialism by choice".

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Licensing code

2009-05-08 Thread Chas. Owens
On Fri, May 8, 2009 at 11:33, Randal L. Schwartz  wrote:
>> ""Chas" == "Chas Owens"  writes:
>
> "Chas> Neither license prevents people from selling the software in question,
> "Chas> but both require that source be available (or made available), so
> "Chas> anyone charging an arm and a leg for it will rapidly find free
> "Chas> versions being made available (see CentOS and RedHat for an example).
>
> No, the Artistic license is much more like a MIT/BSD-style license, which
> basically permits the recipient of your work nearly every right you also
> have. The recipient is free to incorporate your work into their commercial
> product, and never share the source code of the derived work.  Some of us
> consider this a Good Thing.
snip

I missed option c when I skimmed it.

3. You may otherwise modify your copy of this Package in any way, provided
that you insert a prominent notice in each changed file stating how and
when you changed that file, and provided that you do at least ONE of the
following:

a) place your modifications in the Public Domain or otherwise make them
Freely Available, such as by posting said modifications to Usenet or
an equivalent medium, or placing the modifications on a major archive
site such as uunet.uu.net, or by allowing the Copyright Holder to include
your modifications in the Standard Version of the Package.

b) use the modified Package only within your corporation or organization.

c) rename any non-standard executables so the names do not conflict
with standard executables, which must also be provided, and provide
a separate manual page for each non-standard executable that clearly
documents how it differs from the Standard Version.

d) make other distribution arrangements with the Copyright Holder.



-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Perl code for comparing two files

2009-05-08 Thread Richard Loveland
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Mr. Adhikary,

The following will take any number of files as arguments, in the format
you described (I even tested it! :-)). It goes through each line of
those files, stuffing (the relevant part of) each line in a 'seen' hash
(more on that, and other, hash techniques here if you're interested:
http://www.perl.com/pub/a/2006/11/02/all-about-hashes.html).

The code below does not keep track of line numbers as you requested, but
I think the hash technique used here could help you as you approach a
solution to your particular problem.


#!/usr/bin/perl

use strict;
use warnings;
use File::Slurp; # This is where 'read_file' lives

my %seen;

for my $arg ( @ARGV ) {
my @lines = read_file( $arg );
for my $line ( @lines ) {
chomp $line;
my @elems = split / /, $line;
my $value = $elems[1];
$seen{$value}++;
}
}

for my $k ( keys %seen ) {
print $k, "\n" if $seen{$k} > 1;
}


Regards,
Rich Loveland


Anirban Adhikary wrote:
> Hi List
> I am writing a perl code which will takes 2 more files as argument. Then It
> will check the the values of each line of a file with respect with another
> file. If some value matches then it will write the value along with line
> number to another ( say outputfile) file.
> 
> The source files are as follow
> 
> Contents of abc.txt
> 1 2325278241,P0
> 2 2296250723,MH
> 3 2296250724,MH
> 4 2325277178,P0
> 5 7067023316,WL
> 6 7067023329,WL
> 7 2296250759,MH
> 8 7067023453,WL
> 9 7067023455,WL
> 10 555413,EA05
> ###
> Contents of xyz.txt
> 1 7067023453,WL
> 2 31-DEC-27,2O,7038590671
> 3 31-DEC-27,2O,7038596464
> 4 31-DEC-27,2O,7038596482
> 5 2296250724,MH
> 6 31-DEC-27,2O,7038597632
> 7 31-DEC-27,2O,7038589511
> 8 31-DEC-11,2O,7038590671
> 9 7067023455,WL
> 10 31-DEC-27,2O,7038555744
> ###
> Contents of pqr.txt
> 1 2325278241,P0
> 2 7067023316,WL
> 3 7067023455,WL
> 4 2296250724,MH
> 
> 
> 
> 
> 
> 
> For this requirement I have written the following code which works fine for
> 2 input files
> 
> use strict;
> use warnings;
> 
> use Benchmark;
> 
> if(@ARGV < 2) {
> print "Please enter atleast two or more  .orig file names \n";
> exit 0;
> }
> my @file_names = @ARGV;
> chomp(@file_names);
> my @files_to_process;
> 
> for(@file_names) {
> if( -s $_){
> print "File $_ exists\n";
> push(@files_to_process,$_);
> }
> elsif( -e $_) {
> print "File $_ exists but it has zero byte size\n";
> }
> else {
> print "File $_ does not exists \n";
> }
> }
> 
> my $count = @files_to_process;
> if( $count < 2 ) {
> print "Atleast 2 .orig files are required to continue this
> program\n";
> exit 0;
> }
> 
> my $output_file = "outputfile";
> my $value = 0;
> my $start_time = new Benchmark;
> 
> 
> if( $count >= 2 ) {
> while ($count) {
> my ($files_after_processing_pointer,$return_val) =
> create_itermediate_file (\...@files_to_process,$value);
> my @files_after_processing =
> @$files_after_processing_pointer;
> $count = @files_after_processing;
> $value = $return_val;
> @files_to_process = @files_after_processing;
> 
> }
> 
> my $end_time = new Benchmark;
> my $difference = timediff($end_time, $start_time);
> print "It took ", timestr($difference), " to execute the program\n";
> 
> }
> 
> 
> 
> 
> sub create_itermediate_file {
> my $file_pointer = $_[0];
> my $counter = $_[1];
> my @file_content = @$file_pointer;
> 
> if($counter == 0) {
> my($first_file,$second_file) = splice
> (@file_content, 0, 2);
> open my $orig_first, "<", $first_file
> or die "could not open $first_file: $!";
> open my $orig_second, "<", $second_file
> or die "could not open $second_file:
> $!";
> open my $output_fh, ">", $output_file
> or die "could not open $output_file:
> $!";
> 
> my %content_first;
> while  (my $line = <$orig_first>) {
> chomp $line;
> if ($line) {
> 
> my($line_num,$value) = split(" ",$line);
> 
> $content_first{$value} = $line_num;
> }
> }
> 
> my %content_second;
> w