`
weihe6666
  • 浏览: 436166 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Perl-use strict

    博客分类:
  • Perl
阅读更多
perl-use strict


1.什么场合用 use strict

当你的程序有一定的行数时,尤其是在一页放不下时,或者你找不到发生错误的原因时。

2.为什么要用use strict?

众多的原因之一是帮你寻找因为错误拼写造成的错误。比如错误使用了'$recieve_date' 变量,但实际上你在程序中已声明的是 '$receive_date' 变量,这个错误就很难发现。同样,use strict 迫使你把变量的范围缩到最小,使你不必担心同名变量在程序的其它部份发生不良作用。(尽管这是 my 的功能,但是如果你使用 use strict 的话,它会强迫你用 my 声明变量,来达到上述目的)。

使用use strict可以帮我们检查由于拼写而造成的错误,而不必我们自己搜寻。

3.my和use strict
  在使用use strict时结合my一起使用,可以有效的约束变量的书写而导致的问题。

分享到:
评论

相关推荐

    perl-site的压缩包

    use strict; use warnings; use Spreadsheet::ParseXLSX; my $parser = Spreadsheet::ParseXLSX->new(); my $workbook = $parser->parse('example.xlsx'); if ( !defined $workbook ) { die $parser->error(), "....

    perl-Mail-Sendmail

    use strict; my($r_mail) = 'xxxx@163.com'; my($s_mail) = 'root@abc.cn'; my($subject) = '邮件标题'; open(MAIL, '|/usr/lib/sendmail -t'); select(MAIL); print; To: $r_mail From: $s_mail Subject: $subject ...

    perl-scripts实例.tar.gz

    - `use`关键字引入模块,如`use strict;`和`use warnings;`能提高代码质量。 5. **解压和运行实例**: - 解压:首先,你需要一个解压缩工具,如`tar`命令行工具。在终端中运行`tar -zxvf perl-scripts实例.tar.gz...

    windous下perl-gui编程模块 Win32-GUI-1.06-PPM-5.8

    use strict; use warnings; use Win32::GUI; my $main = Win32::GUI::Window->new(-text => "Perl GUI示例", -width => 300, -height => 200); my $button = $main->Button(-text => "点击我", -width => 100, -...

    Perl-by-Example.rar_Perl_Perl by Example_beginners_perl example

    use strict; use warnings; use DateTime; my $dt = DateTime->now(); print $dt->ymd(), "\n"; ``` **面向对象编程** Perl也支持面向对象编程,允许创建类和对象,实现封装、继承和多态。下面是一个简单的类定义...

    perl文件用法

    - Perl的模块提供预定义的功能,使用`use`关键字引入,如`use CGI;`引入Web编程模块。 - `CPAN(Comprehensive Perl Archive Network)`是Perl模块的大型仓库,可以搜索并安装所需模块。 9. **异常处理** - `...

    edit_main_pause_Perl_

    /usr/bin/perl -wuse strict;use warnings;use Genesis;my $host = shift;my $f = new Genesis($host);use Tk;use Encode;use utf8;use Socket;use File::Basename;use Tk::NoteBook;require 'shellwords.pl';#$f-&...

    perl第五版课后习题代码

    use strict; use warnings; my $pi = 3.141592654; # 提示用户输入半径 print "请输入圆的半径: "; chomp(my $radius = ); # 检查半径是否有效 if ($radius ) { print "周长为0\n"; } else { my $circumference...

    周末速成课程-Perl

    use strict; use warnings; open(my $fh, ', '/etc/passwd') or die "Cannot open /etc/passwd: $!"; while (my $line = <$fh>) { chomp $line; my ($username, $password, $uid, $gid, $gecos, $home, $shell) =...

    vim支持perl的插件

    use strict; use warnings; ``` - 若要更改默认的作者和公司信息,可修改`~/.vim/perl-support/templates/Templates`文件中的默认值: ```bash vim ~/.vim/perl-support/templates/Templates |AUTHOR|=...

    ora2pg_perl_list

    use strict; use ExtUtils::Installed; my $inst= ExtUtils::Installed->new(); my @modules = $inst->modules(); foreach(@modules) { my $ver = $inst->version($_) || "???"; printf("%-12s -- %s\n", $_, $ver...

    perl 语言编程 perl精华.pdf

    例如,`use strict;` 和 `use warnings;` 会强制执行严格的语法和发出警告,有助于编写更健壮的代码。 通过熟悉这些Perl命令行选项和技巧,你将能够更高效地利用Perl进行各种任务,无论是快速原型开发、文本处理...

    我找到了perl-perl脚本-usefull-2

    在Perl编程中,"use"语句是引入模块的关键,它允许程序员复用已编写好的代码库,以提高效率和代码质量。当描述中提到"useful"时,我们可以假设这些脚本包含了实用的功能,可能涵盖了诸如文件操作、网络通信、数据...

    Genesis2000 Perl制作电脑V-CUT图纸,源码提供下载

    use strict; use Win32::GUI::DIBitmap(); use Win32::GUI::BitmapInline; use Win32::GUI qw(MB_OK MB_ICONINFORMATION MB_ICONQUESTION MB_YESNOCANCEL MB_YESNO); use Win32::API; use Win32::API::Callback; ...

    perl-poe-smokebox-uploads-rsync:通过 rsync 获取上传的 CPAN 模块

    名称 POE::Component::SmokeBox::Uploads::Rsync - ...use strict; use warnings; use POE; use POE::Component::SmokeBox::Uploads::Rsync; # Create our session to receive events from rsync POE::Session->create

    perl-scripts:有用的Perl脚本和代码片段

    - **模块使用**:`use`关键字引入模块,如`use strict;`和`use warnings;`可以提升代码质量。 5. **错误处理与调试** - **警告和错误**:Perl会发出警告信息,严重错误会导致程序终止。 - **die**和`warn`函数:...

    module-extract-use:提取Perl文件使用的模块

    例如,`use strict;`和`use warnings;`是Perl开发中常见的两个模块,它们分别用于启用严格的语法检查和输出警告信息。 `module-extract-use`工具的主要功能就是识别并列举出Perl脚本中通过`use`语句导入的所有模块...

Global site tag (gtag.js) - Google Analytics